How can change font style on mouse click through xaml and C#?

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#?

Answers


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


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


Need Your Help

Linux Bash Script - Want to run a stopwatch on console while performing other tasks

linux bash

I have been pulling my hair out on this one. I am new to bash scripting and taking a Linux college class. This is not a requirement of any assignment, but just personal development.

Delphi 2010 with earlier compiler

delphi delphi-2010

Is it possible to use de Delphi 7 compiler inside Delphi 2010 IDE?