Click here to Skip to main content
15,886,673 members
Articles / Desktop Programming / XAML

Silverlight Experimental Hacks (SLEX) - EventTrigger, PropertyTrigger, ReactiveTrigger, InvokeMethodAction, StoryBoardAction, etc. for Silverlight

Rate me:
Please Sign up or sign in to vote.
4.81/5 (8 votes)
14 Jan 2010CPOL6 min read 40.8K   241   24  
A set of Silverlight Experimental Hacks (1) A custom implementation of EventTrigger and PropertyTrigger (2) Invoking methods in your view model in MVVM (3) Conditionally invoking triggers and behaviors (4) ReactiveTrigger for exporting your custom events
<navigation:Page x:Class="Slex.Lib.Demo.Views.Demos.EventTrigger" 
           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:slex="clr-namespace:Slex.Lib.Interactions;assembly=Slex.Lib"      
           mc:Ignorable="d"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           d:DesignWidth="640" d:DesignHeight="480"
           Title="EventTrigger Page">
    <Grid x:Name="LayoutRoot">
        <i:Interaction.Triggers>
            <slex:EventTrigger ElementName="txtData" EventName="KeyUp">
                <slex:InvokeCommandAction CommandName="UpdateDataCommand">
                    <slex:InvokeCommandAction.Conditions>
                        <slex:InvokingConditions>
                            <slex:InvokingCondition Property="Argument.Key" Value="A"/>
                            <slex:InvokingCondition ElementName="myCheckBox" Property="IsChecked" Value="True"/>
                        </slex:InvokingConditions>
                    </slex:InvokeCommandAction.Conditions>
                </slex:InvokeCommandAction>
            </slex:EventTrigger>
        </i:Interaction.Triggers>
        <StackPanel>
        <TextBlock FontSize="20" Text="Event Trigger Demo"/>
            <TextBlock Margin="4" TextWrapping="Wrap" 
                       Text="This demo shows how to invoke an action when an event is raised, based on multiple conditions. Type 'A' in the below text box, with the check box checked, to fire the Command in the view model"/>
            <TextBox Margin="4" Name="txtData" Text="Type A 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 A is pressed"/>
            </StackPanel>
        </StackPanel>    
    </Grid>
</navigation:Page>

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