1

I have five buttons like this:

            <Button Name="btnAssets" Grid.Row="1" Margin="7,1,7,1" Click="btnDrawer_Click" >
                <StackPanel >
                    <StackPanel.Background>
                        <ImageBrush ImageSource="/Test;component/Images/DrawerSlid.png" />
                    </StackPanel.Background>
                    <Image Margin="0,0,0,0" Source="/Test;component/Images/DrawerUpper2.png" />
                    <TextBlock Margin="0,10,0,10" TextWrapping="WrapWithOverflow" TextAlignment="Center">Assets</TextBlock>
                    <Image Margin="0,0,0,0" Source="/Test;component/Images/DrawerSlid2.png" />
                </StackPanel>                    
            </Button>

And style trigger for these buttons like this:

    <Style TargetType="StackPanel">
        <Setter Property= "TextBlock.Foreground" Value="White"/>
        <Setter Property= "TextBlock.FontSize" Value="12"/>
        <Style.Triggers>
           <Trigger Property ="IsMouseOver" Value="True">
               <Setter Property= "TextBlock.Foreground" Value="Yellow"/>
               <Setter Property= "TextBlock.FontSize" Value="13"/>
            </Trigger>
        </Style.Triggers>                       
    </Style>

These code works fine. Now I want that When user clicks on any of Button its Foreground color and Font size should be changed. But I can not find any easy solution. How can do this is via xaml or via c#?

user1336491
  • 57
  • 1
  • 9
  • Check out EventTrigger. This (http://stackoverflow.com/questions/942548/setting-a-property-with-an-eventtrigger) SO question has a couple of good answers about the topic – K Mehta Jun 14 '12 at 06:29

2 Answers2

1

You can use trigger "IsPressed" in Button style template. See this http://geekswithblogs.net/cskardon/archive/2008/06/20/roundedbutton-button-style-wpf.aspx

Ribtoks
  • 6,634
  • 1
  • 25
  • 37
0

Buttons have a different way of being constructed in WPF so there is a little more work involved in getting the trigger for a button to work as you wish. The steps are usually:

  1. Derive from the Decorator base class to create a template for your own button
  2. Create your own control template for the button in XAML
  3. Hook up the button to your custom template!

A fine working article and example is given here: http://www.wiredprairie.us/journal/2006/09/wpf_decorators_build_your_own.html

SalGad
  • 2,991
  • 2
  • 18
  • 25