Click here to Skip to main content
15,881,872 members
Articles / Desktop Programming / WPF

WPF Extensibility Hacks or WEX - Includes EventTrigger, ReactiveTrigger, InvokeMethodAction, InvokeCommandAction etc.

Rate me:
Please Sign up or sign in to vote.
5.00/5 (6 votes)
14 Jan 2010CPOL4 min read 37.9K   353   24  
A set of extensibility hacks for WPF. A few interesting triggers and actions, including EventTrigger, ReactiveTrigger, InvokeMethodAction, and InvokeCommandAction. Also allows invoking Triggers and Actions based on Conditions.
<UserControl x:Class="Wex.Lib.Demo.Views.Demos.PropertyTrigger" 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"      
           xmlns:wex="clr-namespace:Wex.Lib.Interactions;assembly=Wex.Lib"      
           mc:Ignorable="d"
           d:DesignWidth="640" d:DesignHeight="480">
    <Grid x:Name="LayoutRoot">
        <i:Interaction.Triggers>
            <!--
            <wex:PropertyTrigger ElementName="txtData" Property="Text">
                <wex:InvokeCommandAction CommandName="UpdateDataCommand">
                    <wex:InvokeCommandAction.Conditions>
                    <wex:InvokingConditions>
                        <wex:InvokingCondition Value="Hello"/>
                        <wex:InvokingCondition ElementName="myCheckBox" Property="IsChecked" Value="True"/>
                    </wex:InvokingConditions>
                  </wex:InvokeCommandAction.Conditions>
                </wex:InvokeCommandAction>
            </wex:PropertyTrigger>
            -->
        </i:Interaction.Triggers>
        <StackPanel>
            <TextBlock FontSize="20" Text="Property Trigger Demo"/>
            <TextBlock Margin="4" TextWrapping="Wrap" 
                       Text="This demo shows how to invoke an action when a property is changed, based on multiple conditions. Type 'Hello' in the below text box, with the check box checked, to fire the command"/>
            <TextBox Margin="4" Name="txtData" Text="Type Hello here, with the checkbox checked"/>
            <StackPanel Background="LightGray" Margin="5">
                <TextBlock Margin="4" Text="{Binding Data}" FontSize="14"/>
                <CheckBox Name="myCheckBox" Content="Check to Fire The Command if 'Hello' is entered"/>
            </StackPanel>
        </StackPanel>
    </Grid>
</UserControl>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
India India
Architect, Developer, Speaker | Wannabe GUT inventor & Data Scientist | Microsoft MVP in C#

Comments and Discussions