Set the DataContext
property of the window:
<Window x:Class="MimicView.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MimicView"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance local:MainWindowViewModel}"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<DataTemplate DataType="{x:Type local:ViewModel1}">
<local:View1/>
</DataTemplate>
</Window.Resources>
<Window.DataContext>
<local:MainWindowViewModel />
</Window.DataContext>
<Grid>
<ContentControl Content="{Binding viewModel1}"></ContentControl>
</Grid>
</Window>
This only sets the design time DataContext
:
d:DataContext="{d:DesignInstance local:MainWindowViewModel}"
You should also set the actual DataContext
property:
<Window.DataContext>
<local:MainWindowViewModel />
</Window.DataContext>
0
solved Unable to Render ContentControl inside Window [closed]