Search This Blog

Wednesday, August 31, 2011

Set property in View from ViewModel in MVVM using Interaction Triggers; Set View's property from ViewModel without code behind in Silverlight 4.0

We have a View which is a Window control with DialogResult property and we want to set this property to True without using code behind.

<controls:ChildWindow  x:Class="WebClient.Views.ConfWorkerView"

   xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
   xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
   xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions”
Name="Window" >

  <UserControl>
    <Grid>
    <Button HorizontalAlignment="Right" Content="Save"  Command="{Binding SaveCommand}" >
          <i:Interaction.Triggers>
            <i:EventTrigger EventName="Click">
               <ei:ChangePropertyAction PropertyName="DialogResult" Value="True" TargetName="Window"/>
            </i:EventTrigger>
          </i:Interaction.Triggers>
       </Button>
    <Grid>
  <UserControl>
</controls:ChildWindow>

No comments:

Post a Comment

If you like this post, please leave a comment :)