Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use the Expression Blend SDK for invoking commands in response to events in general, however my experience has been that not all events are supported by EventTrigger.</p> <p>For example, this seems to work:</p> <pre><code>&lt;Label Content="LabelText"&gt; &lt;i:Interaction.Triggers&gt; &lt;i:EventTrigger EventName="MouseMove"&gt; &lt;i:InvokeCommandAction Command="{Binding IsVisibleChangedCommand, Mode=OneWay}"/&gt; &lt;/i:EventTrigger&gt; &lt;/i:Interaction.Triggers&gt; &lt;/Label&gt; </code></pre> <p>But this doesn't:</p> <pre><code>&lt;Label Content="LabelText"&gt; &lt;i:Interaction.Triggers&gt; &lt;i:EventTrigger EventName="IsVisibleChanged"&gt; &lt;i:InvokeCommandAction Command="{Binding IsVisibleChangedCommand, Mode=OneWay}"/&gt; &lt;/i:EventTrigger&gt; &lt;/i:Interaction.Triggers&gt; &lt;/Label&gt; </code></pre> <p>I'm not sure why, but Blend SDK does not seem to like the IsVisible property. You can do something similar but using Visibility (instead of IsVisible) with a PropertyChangedTrigger like this:</p> <pre><code>&lt;Label x:Name="label1" Content="LabelText"&gt; &lt;i:Interaction.Triggers&gt; &lt;ei:PropertyChangedTrigger Binding="{Binding Visibility, ElementName=label1}"&gt; &lt;i:InvokeCommandAction Command="{Binding IsVisibleChangedCommand, Mode=OneWay}"/&gt; &lt;/ei:PropertyChangedTrigger&gt; &lt;/i:Interaction.Triggers&gt; &lt;/Label&gt; </code></pre> <p>BTW - Here are the namespaces:</p> <pre><code>xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" </code></pre> <p>Also, here is another solution to your specific problem that does not require the Blend SDK:</p> <p>Instead of directly binding an event to a command, you can bind the Visibility property of your object to a viewmodel property and execute the command from the property setter like this:</p> <p>View:</p> <pre><code>&lt;UserControl x:Class="SampleApp.Views.EventBindingDemoView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="200" Width="200"&gt; &lt;UserControl.Resources&gt; &lt;BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" /&gt; &lt;/UserControl.Resources&gt; &lt;Grid&gt; &lt;Label Content="LabelText" Visibility="{Binding Path=ElementIsVisible, Mode=TwoWay, Converter={StaticResource BooleanToVisibilityConverter}}"/&gt; &lt;!-- The rest of your view here --&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p>ViewModel (ViewModelBase should implement INotifyPropertyChanged and OnPropertyChanged(string propertyName) ):</p> <pre><code>public class EventBindingDemoViewModel : ViewModelBase { private bool ElementIsVisibleField = true; // or false if it should initially be hidden public bool ElementIsVisible { get { return this.ElementIsVisibleField; } set { if (this.ElementIsVisibleField != value) { this.ElementIsVisibleField = value; this.OnPropertyChanged("ElementIsVisible"); // Execute command this.IsVisibleChangedCommand.Execute(null); } } } public ICommand IsVisibleChangedCommand; // The rest of your viewmodel here } </code></pre> <p>Either way should work.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload