Saturday, 31 March 2012

PropertyTrigger In Wpf:-

We can change the property of control based on another property using property triggers.The below code is simple example of property trigger which display the text based on checkbox.

<Window x:Class="WpfPropertyTriggers.MainWindow"
        Title="MainWindow" Height="350" Width="525">
            <!--Add the style for check box-->
            <Style TargetType="{x:Type CheckBox}" x:Key="cbStyle">
                    <!--Check whether checkbox checked or not-->
                    <Trigger Property="IsChecked" Value="true">
                        <!--If checkbox is checked then display the text and set the color-->
                        <Setter Property="Foreground" Value="Red"></Setter>
                        <Setter Property="Content" Value="You checked the box..."></Setter>
            <ColumnDefinition Width="150"></ColumnDefinition>
        <!--Apply the style resource for check box-->
        <CheckBox Name="cb" Grid.Column="0" Style="{StaticResource cbStyle}"></CheckBox>

Let me know, if you have any feedback. Mail me for source code. Enjoy reading my articles…

No comments:

Post a Comment