Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your problem is that the command is getting the context from its template and there it cannot access the root of the ViewModel. Add this class to your solution:</p> <pre><code>public class DataContextProxy : FrameworkElement { public DataContextProxy() { this.Loaded += new RoutedEventHandler(DataContextProxyLoaded); } void DataContextProxyLoaded(object sender, RoutedEventArgs e) { Binding binding = new Binding(); if (!String.IsNullOrEmpty(BindingPropertyName)) { binding.Path = new PropertyPath(BindingPropertyName); } binding.Source = this.DataContext; binding.Mode = BindingMode; this.SetBinding(DataContextProxy.DataSourceProperty, binding); } public Object DataSource { get { return (Object)GetValue(DataSourceProperty); } set { SetValue(DataSourceProperty, value); } } public static readonly DependencyProperty DataSourceProperty = DependencyProperty.Register("DataSource", typeof(Object), typeof(DataContextProxy), null); public string BindingPropertyName { get; set; } public BindingMode BindingMode { get; set; } } </code></pre> <p>then use it in you XAML like so:</p> <pre><code> &lt;UserControl.Resources&gt; &lt;library:DataContextProxy x:Key="DataContextProxy"/&gt; &lt;/UserControl.Resources&gt; </code></pre> <p>Then in your command binding:</p> <pre><code>&lt;Button Tag="{Binding WorkFlowCompId}"&gt; &lt;Button.Content&gt; &lt;TextBlock Text="{Binding ComponentName,Mode=TwoWay}"/&gt; &lt;/Button.Content&gt; &lt;i:Interaction.Triggers&gt; &lt;i:EventTrigger EventName="Click"&gt; &lt;i:InvokeCommandAction Command="{Binding DataSource.ComponentSelected, Source={StaticResource DataContextProxy}" CommandParameter="{Binding WorkFlowCompId,Mode=TwoWay}" &gt; &lt;/i:InvokeCommandAction&gt; &lt;/i:EventTrigger&gt; &lt;/i:Interaction.Triggers&gt; &lt;/Button&gt; </code></pre>
 

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