Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I bind a control's command to a child viewmodel command in an MVVM scenario?
    primarykey
    data
    text
    <p>I have a window in WPF based upon a viewmodel. The viewmodel includes a child viewmodel that can be switched at runtime. Each child viewmodel has its own commands. The parent view contains a ribbon with buttons that need to bind to the current child viewmodels commands. To switch views I use a content control in the parent view that uses data templates. Each possible child view is a user control that binds to the appropriate viewmodel (that bit works).</p> <pre><code> &lt;!-- Switchable area --&gt; &lt;ContentControl Content="{Binding ChildViewModel}"&gt; &lt;ContentControl.Resources&gt; &lt;DataTemplate DataType="{x:Type vm:VersionsViewModel}"&gt; &lt;embeddable:VersionsView /&gt; &lt;/DataTemplate&gt; &lt;DataTemplate DataType="{x:Type vm:LockListViewModel}"&gt; &lt;embeddable:LockListView /&gt; &lt;/DataTemplate&gt; &lt;/ContentControl.Resources&gt; &lt;/ContentControl&gt; </code></pre> <p>So for example, one of my child viewmodels has a refresh command. I want this to appear in the main view in a ribbon button. I've tried setting the binding to the following XAML but it never binds so the command isn't called. What am I doing wrong?</p> <pre><code>&lt;telerik:RadRibbonButton Size="Large" Text="Refresh" LargeImage="..\Images\Ribbon\32x32\Refresh.png" Command="{Binding ChildView.RefreshCommand}" telerik:KeyTipService.AccessText="R"/&gt; </code></pre> <p>Elsewhere in the main view I have bindings for data that comes from the child viewmodel and works fine so I'm really confused! For example, this is the binding I use to get the title for the window.</p> <pre><code>Title="{Binding ChildViewModel.Title,FallbackValue='My System'}" </code></pre>
    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.
 

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