Note that there are some explanatory texts on larger screens.

plurals
  1. POContentcontrol doesn't find my datatemplate it's ViewModel
    text
    copied!<p>I'm using WPF, MVVM &amp; PRISM. I got a datatemplate in my View linked to a ViewModel UC2002_RFPBeheren_ViewModel cause the page were this code is included is linked to another ViewModel and I want the Button to have UC2002_RFPBeheren_ViewModel as ViewModel.</p> <p><strong>The datacontext of this page is UC2002_RFPBeheren_ProjectInfo_ViewModel but I want the SaveButton to use the ViewModel UC2002_RFPBeheren_ViewModel</strong></p> <p>Here is my code:</p> <pre><code>&lt;UserControl.Resources&gt; &lt;ResourceDictionary&gt; &lt;ResourceDictionary.MergedDictionaries&gt; &lt;ResourceDictionary Source="../Resources/RFPModuleResources.xaml" /&gt; &lt;ResourceDictionary&gt; &lt;DataTemplate x:Key="SaveButton" DataType="{x:Type vm:UC2002_RFPBeheren_ViewModel}"&gt; &lt;Button Command="{Binding SaveRFPCommand}"&gt;Save&lt;/Button&gt; &lt;/DataTemplate&gt; &lt;/ResourceDictionary&gt; &lt;/ResourceDictionary.MergedDictionaries&gt; &lt;/ResourceDictionary&gt; &lt;/UserControl.Resources&gt; &lt;StackPanel HorizontalAlignment="Right" Orientation="Horizontal"&gt; &lt;ContentControl ContentTemplate="{StaticResource SaveButton}"/&gt; &lt;Button Command="{Binding CloseTabCommand}"&gt;Close&lt;/Button&gt; &lt;/StackPanel&gt; </code></pre> <p>Although the SaveButton displays but don't reacts on my command. <br /> Do I forget something or is there another way to solve this? <br /> Thanks in advance ;) !</p> <p>=================================================================================</p> <p><strong>EDIT:</strong></p> <p>So I made some changes but it still doesn't work.</p> <p>Code example:</p> <pre><code>&lt;UserControl.Resources&gt; &lt;ResourceDictionary&gt; &lt;ResourceDictionary.MergedDictionaries&gt; &lt;ResourceDictionary Source="../Resources/RFPModuleResources.xaml" /&gt; &lt;ResourceDictionary&gt; &lt;DataTemplate x:Key="SaveButton" DataType="{x:Type vm:UC2002_RFPBeheren_ViewModel}"&gt; &lt;Button Command="{Binding SaveRFPCommand}"&gt;Save&lt;/Button&gt; &lt;/DataTemplate&gt; &lt;/ResourceDictionary&gt; &lt;/ResourceDictionary.MergedDictionaries&gt; &lt;/ResourceDictionary&gt; &lt;/UserControl.Resources&gt; </code></pre> <p>I set this property in the ViewModel of the page</p> <pre><code>public UC2002_RFPBeheren_ViewModel MySaveVM { get; set; } </code></pre> <p>My stackpanel looks now like this:</p> <pre><code>&lt;StackPanel HorizontalAlignment="Right" Orientation="Horizontal"&gt; &lt;ContentControl Content="{Binding MySaveVM}" ContentTemplate="{StaticResource SaveButton}"/&gt; &lt;Button Command="{Binding CloseTabCommand}"&gt;Close&lt;/Button&gt; &lt;/StackPanel&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