Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>what happens if you set your UV2002_RFPBeheren_ViewModel instance as the content for the ContentPresenter?</p> <pre><code> &lt;ContentControl Content="{Binding MyUV2002_RFPBeheren_ViewModel}"/&gt; </code></pre> <p>the DataTemplate just say how your Viewmodel should be displayed, but you have to set the DataContext or Binding to the instance of your viewmodel. </p> <p>EDIT:</p> <p>example</p> <pre><code> public class VMFoo { public UV2002_RFPBeheren_ViewModel MySaveVM {get; set;} } </code></pre> <p>xaml </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;UserControl.DataContext&gt; &lt;x:local VMFoo/&gt; &lt;/UserControl.DataContext&gt; &lt;StackPanel HorizontalAlignment="Right" Orientation="Horizontal"&gt; &lt;ContentControl Content="{Binding MySaveVM}"/&gt; &lt;Button Command="{Binding CloseTabCommand}"&gt;Close&lt;/Button&gt; &lt;/StackPanel&gt; </code></pre> <p>EDIT: Small working sample</p> <pre><code>&lt;Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:WpfApplication1="clr-namespace:WpfApplication1" Title="MainWindow" Height="350" Width="525"&gt; &lt;Window.Resources&gt; &lt;ResourceDictionary&gt; &lt;DataTemplate DataType="{x:Type WpfApplication1:UV2002_RFPBeheren_ViewModel}"&gt; &lt;Button Command="{Binding SaveRFPCommand}"&gt;Save&lt;/Button&gt; &lt;/DataTemplate&gt; &lt;/ResourceDictionary&gt; &lt;/Window.Resources&gt; &lt;Grid&gt; &lt;Grid.DataContext&gt; &lt;WpfApplication1:VMFoo/&gt; &lt;/Grid.DataContext&gt; &lt;StackPanel HorizontalAlignment="Right" Orientation="Horizontal"&gt; &lt;ContentControl Content="{Binding MySaveVM}"/&gt; &lt;Button Command="{Binding CloseTabCommand}"&gt;Close&lt;/Button&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>Viewmodels</p> <pre><code>public class VMFoo { public VMFoo() { this.MySaveVM = new UV2002_RFPBeheren_ViewModel(); } public UV2002_RFPBeheren_ViewModel MySaveVM { get; set; } } public class UV2002_RFPBeheren_ViewModel { private DelegateCommand _save; public ICommand SaveRFPCommand { get{if(this._save==null) { this._save = new DelegateCommand(()=&gt;MessageBox.Show("success"),()=&gt;true); } return this._save; } } } </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