WPF [SOLVED]: WPF- Mouse Over effect not taking place

WPF [SOLVED]: WPF- Mouse Over effect not taking place

Home Forums Frameworks WPF WPF [SOLVED]: WPF- Mouse Over effect not taking place

Tagged: , ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #246816

    Cloudy Point
    Keymaster

    QuestionQuestion

    I have a set of buttons created in WPF. I am adding two triggers to the buttons, MouseOver and IsPressed. However , only the IsPressed trigger is working but not the MouseOver effect. I want to be able to highlight the button with mouse cursor and then it changes to a different color. What did I miss?

    XAML:

    <Setter Property="Template">
            <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
            <Border x:Name="Border" >
         <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                       </Border>
                     <ControlTemplate.Triggers>
                      <Trigger Property="IsMouseOver" Value="True">
    
                  <Setter Property="Background" Value="DarkGoldenrod"/>
                                </Trigger>
    
               <Trigger Property="IsPressed" Value="True">
         <Setter TargetName="Border" Property="BorderThickness" Value="10,10,0,0"/>
    
                  </Trigger>
                     </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
                </Setter>
    

    EDITED:

    <Style.Triggers>
                        <Trigger Property="IsPressed" Value="True">
    
                            <Setter Property="BorderThickness" Value="10,10,0,0">
    
                            </Setter>
                            <Setter Property="Opacity" Value="0.2"/>
    
                        </Trigger>
    
                    </Style.Triggers>
    

    #246817

    Cloudy Point
    Keymaster

    Accepted AnswerAnswer

    You’re missing TargetName=”Border” in your DarkGoldenrod trigger.

    Source: https://stackoverflow.com/questions/47916934/wpf-mouse-over-effect-not-taking-place
    Author: Rowbear
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.