Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It's not possible to override ListBoxItem triggered brushes #3900

Closed
punker76 opened this issue Aug 6, 2020 · 1 comment · Fixed by #3942, #3948 or #3960
Closed

It's not possible to override ListBoxItem triggered brushes #3900

punker76 opened this issue Aug 6, 2020 · 1 comment · Fixed by #3942, #3948 or #3960
Assignees
Labels
Milestone

Comments

@punker76
Copy link
Member

punker76 commented Aug 6, 2020

Describe the bug

This issue results from #3899

It's not possible to override ListBoxItem triggered brushes via own style like

<Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource MahApps.Styles.ListBoxItem}">
    <Setter Property="Controls:ItemHelper.HoverBackgroundBrush" Value="{DynamicResource MahApps.Brushes.Gray}" />
    <Setter Property="Controls:ItemHelper.HoverSelectedBackgroundBrush" Value="{DynamicResource MahApps.Brushes.Gray1}" />
    <Style.Triggers>
        <EventTrigger RoutedEvent="PreviewMouseRightButtonDown">
            <BeginStoryboard x:Name="BeginStoryboard_IsPressed">
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames Duration="0:0:0"
                                                   Storyboard.TargetProperty="Background">
                        <!--
                            Note: It's not possible to use DynamicResource inside a Storyboard.
                            So use StaticResource or a static Brush instead.
                         -->
                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Brushes.Red}" />
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
        <EventTrigger RoutedEvent="PreviewMouseRightButtonUp">
            <RemoveStoryboard BeginStoryboardName="BeginStoryboard_IsPressed" />
        </EventTrigger>
    </Style.Triggers>
</Style>

Expected behavior

The Background of the ListBoxItem should be changed if the user clicks the right mouse button.

mahapps_listbox_hover_better

Actual behavior

Nothing happens.

Environment

MahApps.Metro version: v2.2.0
Target Framework: .Net Core 3.1 (v4.5.2, v4.7.2)

Screenshots

mahapps_listbox_hover

@PhyxionNL
Copy link

@punker76, these changes break if you're using an alternation index background on the container:

<Style.Triggers> <Trigger Property="ItemsControl.AlternationIndex" Value="0"> <Setter Property="Background" Value="{DynamicResource MahApps.Brushes.Gray10}" /> </Trigger> </Style.Triggers>

It's now no longer possible to set a normal background for these while retaining the hover backgrounds etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment