Re-using UI in WPF from a Resource - wpf

I have a several tabs on UI where on each tab I need the below:
<StackPanel Orientation="Horizontal">
<Button Content="<" Command="{Binding MoveToPreviousCommand}" />
<TextBlock Text="{Binding SelectedItem.Name}" />
<Button Content=">" Command="{Binding MoveToNextCommand}" />
</StackPanel>
Is there a way to avoid replicating this code in XAML for each tab by specifying the above for example in the Resources only once and pointing into that resource under each tab?

Using ContentControl
<Window.Resources>
<StackPanel x:Key="Content" x:Shared="False" Orientation="Horizontal">
<Button Content="<" Command="{Binding MoveToPreviousCommand}" />
<TextBlock Text="{Binding SelectedItem.Name}" />
<Button Content=">" Command="{Binding MoveToNextCommand}" />
</StackPanel>
<DataTemplate x:Key="template1">
<StackPanel Orientation="Horizontal">
<Button Content="<" Command="{Binding MoveToPreviousCommand}" />
<TextBlock Text="{Binding SelectedItem.Name}" />
<Button Content=">" Command="{Binding MoveToNextCommand}" />
</StackPanel>
</DataTemplate>
</Window.Resources>
<StackPanel>
<ContentControl Content="{StaticResource Content}"></ContentControl>
<ContentControl Name="contCtrl" ContentTemplate="{StaticResource template1}" Content="This is the content of the content control."/>
</StackPanel>
using usercontrol
<UserControl x:Class="WpfApplication2.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<StackPanel Orientation="Horizontal">
<Button Content="<" Command="{Binding MoveToPreviousCommand}" />
<TextBlock Text="{Binding SelectedItem.Name}" />
<Button Content=">" Command="{Binding MoveToNextCommand}" />
</StackPanel>
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
xmlns:local="clr-namespace:WpfApplication2">
<Grid>
<local:UserControl1></local:UserControl1>
</Grid>

Related

WPF - Binding inside usercontrol content

I'm new in WPF and I have problems encountered. Why the binding of ListView ItemSource inside the sectionControls:ViewDefaultLayout element is not working. But when I try to remove the ListView element outside of the sectionControls:ViewDefaultLayout element the categories are showing.
CategoriesControl.xaml
<UserControl x:Class="POS.Wpf.Controls.CategoriesControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:POS.Wpf.Controls"
xmlns:sectionControls="clr-namespace:POS.Wpf.Controls.Section"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Loaded="UserControl_Loaded"
x:Name="categoryUserControl">
<Grid>
<sectionControls:ViewDefaultLayout Title="Categories" Add="ViewDefaultLayout_Add" Delete="ViewDefaultLayout_Delete">
<ListView ItemsSource="{Binding DataContext.Categories}">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" />
</GridView>
</ListView.View>
</ListView>
</sectionControls:ViewDefaultLayout>
</Grid>
ViewDefaultLayout.xaml
<UserControl x:Class="POS.Wpf.Controls.Section.ViewDefaultLayout"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:POS.Wpf.Controls.Section"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Template>
<ControlTemplate TargetType="UserControl">
<DockPanel>
<Grid DockPanel.Dock="Top">
<Label Content="{Binding Title}" Margin="10" Style="{StaticResource BoldLargeLabel}"></Label>
</Grid>
<Border Padding="10">
<DockPanel>
<Border BorderBrush="{x:Null}" DockPanel.Dock="Top" Margin="0 0 0 5">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="135" />
</Grid.ColumnDefinitions>
<Grid>
<TextBox Text="Search" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Foreground="#FFE4DFDF" VerticalContentAlignment="Center" FontSize="15"></TextBox>
<Button x:Name="SearchButton" Padding="5" Background="{x:Null}" BorderBrush="{x:Null}" HorizontalAlignment="Right" Click="SearchButton_Click">
<materialDesign:PackIcon Foreground="#A2A6AC" Kind="Search" Width="30" Height="30" />
</Button>
</Grid>
<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
<Button x:Name="AddButton" Padding="5" Background="{x:Null}" HorizontalAlignment="Right" Margin="0 0 5 0" Click="AddButton_Click">
<materialDesign:PackIcon Foreground="#A2A6AC" Kind="Add" Width="50" Height="30" />
</Button>
<Button x:Name="DeleteButton" Padding="5" Background="{x:Null}" HorizontalAlignment="Right" Click="DeleteButton_Click">
<materialDesign:PackIcon Foreground="#A2A6AC" Kind="Delete" Width="50" Height="30" />
</Button>
</StackPanel>
</Grid>
</Border>
<ContentPresenter />
</DockPanel>
</Border>
</DockPanel>
</ControlTemplate>
</UserControl.Template>

How to apply theme effect on complete application in wpf c# when select perticular control

Hello friend i have created wpf theme in which i place buttons so my questions is when i click the particular button the complete application color should change below is my code behind and xaml.
<UserControl x:Class="Alyex.Exchange.UserControls.UCUserThemes"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxd="http://schemas.devexpress.com/winfx/2008/xaml/docking"
xmlns:dxp="http://schemas.devexpress.com/winfx/2008/xaml/printing"
xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:dxga="http://schemas.devexpress.com/winfx/2008/xaml/gauges"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxthm="clr-namespace:DevExpress.Xpf.Utils.Themes;assembly=DevExpress.Xpf.Core.v14.2"
xmlns:common="clr-namespace:Alyex.Common;assembly=Alyex.Common"
xmlns:commonUIHelpers="clr-namespace:Alyex.CommonUI.UIHelpers;assembly=Alyex.CommonUI"
xmlns:commonResource="clr-namespace:Alyex.Common.Resources;assembly=Alyex.Common"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
d:DesignHeight="600" d:DesignWidth="900" ToolTip="WindowsTransparency">
<UserControl.Resources>
<common:DebugConverter x:Key="debugConverter"/>
<common:LanguagetoHorizontalContentAligmentConverter x:Key="ContentAlignmentConverter"/>
<common:AllowInsertToNewNodeVisibilityConverter x:Key="newNodeVisibilityConverter"/>
<common:BoolToStatusConverter x:Key="boolToStatusConverter"/>
<DataTemplate x:Key="toolbarCustomization">
<dxb:BarManagerActionContainer>
<!--Remove Export Button-->
<dxb:RemoveBarItemAndLinkAction ItemName="export" />
<!--Remove Email Sending Button-->
<dxb:RemoveBarItemAndLinkAction ItemName="email" />
<!--Remove Save Button-->
<dxb:RemoveBarItemAndLinkAction ItemName="save" />
</dxb:BarManagerActionContainer>
</DataTemplate>
<DataTemplate x:Key="PageHeader" >
<DockPanel>
<StackPanel Orientation="Vertical">
<dxe:ImageEdit x:Name="logo" HorizontalAlignment="Left"
Margin="0,0,0,1" BorderThickness="0"
VerticalAlignment="Top" IsPrintingMode="True"
HorizontalContentAlignment="Stretch"
CausesValidation="False"
Source="/Alyex.CommonUI;component/Images/Alx/ReportHeader.jpg"
Stretch="Fill"
Height="40"
Width="238"
/>
<dxe:TextEdit IsPrintingMode="True"
Text="{Binding Source={x:Static sys:DateTime.Now},Mode=OneWay, StringFormat='{}{0:dddd, dd-MMMM-yyyy hh:mm tt}'}"
dxp:ExportSettings.TargetType="Text"
Background="Transparent"
Margin="0,0,0,3"
></dxe:TextEdit>
</StackPanel>
<dxe:TextEdit Grid.Column="1" Grid.RowSpan="2"
EditValue="{Binding Content,Mode=OneWay}"
dxp:ExportSettings.TargetType="Text"
FontSize="25" FontWeight="ExtraBold"
Margin="10,0,0,1"
Background="Transparent"
HorizontalAlignment="Center"
MaxWidth="{Binding Path=UsablePageWidth, Mode=OneWay}"
/>
</DockPanel>
</DataTemplate>
<DataTemplate x:Key="PageFooter">
<dxe:TextEdit
HorizontalContentAlignment="Center"
Width="{Binding Path=UsablePageWidth, Mode=OneWay}"
dxp:ExportSettings.TargetType="PageNumber"
dxp:PageNumberExportSettings.Kind="NumberOfTotal"
dxp:PageNumberExportSettings.Format="Page {0} of {1}" />
</DataTemplate>
<DataTemplate x:Key="StatusIndicator">
<StackPanel Orientation="Horizontal">
<dxga:StateIndicatorControl x:Name="lampRecordStatusIndicator" StateIndex="{Binding Path=RowData.Row.IsActiveRecord}" Width="20" Height="20">
<dxga:StateIndicatorControl.Model>
<dxga:LampStateIndicatorModel />
</dxga:StateIndicatorControl.Model>
</dxga:StateIndicatorControl>
<TextBlock x:Name="txtBlkRecordStatus" VerticalAlignment="Center" Text="{Binding Path=RowData.Row.IsActiveRecord, Converter={StaticResource boolToStatusConverter}, Mode=OneWay}"></TextBlock>
</StackPanel>
</DataTemplate>
</UserControl.Resources>
<Grid x:Name="grdContainer" Margin="3,3,3,3">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<dxb:BarManager Name="barManager" CreateStandardLayout="True">
<dxd:DockLayoutManager x:Name="dockLayotManager" AllowDocumentSelector="False" Background="Transparent">
<dxd:LayoutGroup x:Name="layotGrp">
<dxd:DocumentGroup x:Name="docmntGrpUserThemes" ClosePageButtonShowMode="InAllTabPageHeaders"
ShowDropDownButton="False" CaptionLocation="Bottom" AllowFloat="False" AllowDrag="False">
<dxd:DocumentPanel x:Name="docmntPnlUserThemes" Caption="UserThemes"
AllowClose="False" AllowFloat="False" ToolTip="UserThemes"
AllowDrag="False">
<DockPanel>
<dxe:ListBoxEdit Name="lstboxwindowsTransparancy" Margin="10" SelectedIndexChanged="lstboxWindowsTransparency_SelectedIndexChanged"
ItemsSource="{Binding Source={x:Static dx:Theme.Themes},Mode=OneWay}">
<dxe:ListBoxEdit.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Height="{Binding (FrameworkElement.ActualHeight), RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}" Orientation="Vertical" />
</ItemsPanelTemplate>
</dxe:ListBoxEdit.ItemsPanel>
<dxe:ListBoxEdit.ItemTemplate>
<DataTemplate>
<Button Width="130" Height="100">
<Button.Content>
<StackPanel>
<Image Source="{Binding SmallGlyph}" Width="40"/>
<AccessText TextWrapping="Wrap" Text="{Binding}" HorizontalAlignment="Center"></AccessText>
</StackPanel>
</Button.Content>
</Button>
</DataTemplate>
</dxe:ListBoxEdit.ItemTemplate>
</dxe:ListBoxEdit>
</DockPanel>
</dxd:DocumentPanel>
</dxd:DocumentGroup>
</dxd:LayoutGroup>
</dxd:DockLayoutManager>
</dxb:BarManager>
</Grid>
and this is my code behind
public partial class UCUserThemes : UserControl
{
public UCUserThemes()
{
InitializeComponent();
}
private void lstboxWindowsTransparency_SelectedIndexChanged(object sender, RoutedEventArgs e)
{
DXSplashScreen.Show<WaitDialogSSView>();
DevExpress.Xpf.Core.ThemeManager.ApplicationThemeName = DevExpress.Xpf.Core.Theme.Default.ToString();
ImageSource img = new BitmapImage(((DevExpress.Xpf.Core.Theme)lstboxwindowsTransparancy.SelectedItem).SmallGlyph);
ThemeManager.ApplicationThemeName = Theme.Office2010BlackFullName;
DXSplashScreen.Close();
}
}
}
ThemeManager.ApplicationThemeName= "Your Theme";

WPF ContentControl DataTemplate not updating value

I have no idea what's happening here. When I bind directly to a TextBox the value can be edited, but I want to bind in a ContentControl.
Why doesn't the ContentControl update the ViewModel?
<Window x:Class="WTFWPF.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:local="clr-namespace:WTFWPF"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="MainWindow"
Width="525"
Height="350"
DataContext="{DynamicResource ViewModel}"
mc:Ignorable="d">
<Window.Resources>
<local:MainViewModel x:Key="ViewModel" />
<DataTemplate DataType="{x:Type sys:Int32}">
<TextBox Text="{Binding Path=., UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</Window.Resources>
<StackPanel>
<TextBlock Margin="5" Text="{Binding Number}" />
<TextBox Margin="5" Text="{Binding Number, UpdateSourceTrigger=PropertyChanged}" />
<ContentControl Margin="5" Content="{Binding Number}" />
</StackPanel>
</Window>
This seem to work fine, not sure why your version doesn't work though.
<Window.Resources>
<wpfApplication1:MainViewModel x:Key="ViewModel" />
<DataTemplate x:Key="NumberTemplate">
<TextBox Text="{Binding Path=Number, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</Window.Resources>
<StackPanel>
<TextBlock Margin="5" Text="{Binding Number}" />
<TextBox Margin="5" Text="{Binding Number, UpdateSourceTrigger=PropertyChanged}" />
<ContentControl Margin="5"
Content="{Binding}"
ContentTemplate="{StaticResource NumberTemplate}" />
</StackPanel>
Another way of making it work is to change the binding in the template:
<TextBox Text="{Binding Path=DataContext.Number,
RelativeSource={RelativeSource AncestorType=ContentControl}, UpdateSourceTrigger=PropertyChanged}" />
Unfortunately I can't explain why your version doesn't work.

Resize my user controls content with change in size of window or document panel

I have few buttons on click, they display a user control with images. when i resize any one of them, the images starts hiding. but i want them to expand and shrink with resize. please tell me how to achieve this.
OtherPanelView.xaml
<UserControl x:Class="DXDockingMVVMTest1.Views.OtherPanelView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" Background="Orange">
<Grid>
<Image HorizontalAlignment="Left" Height="23" Margin="96,104,0,0" TextWrapping="Wrap" Source="{Binding Image}" VerticalAlignment="Top" Width="120"/>
</Grid>
</UserControl>
PanelView.xaml
<UserControl x:Class="DXDockingMVVMTest1.Views.PanelView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" Background="#FF47DAB4">
<Grid>
<Image HorizontalAlignment="Left" Height="23" Margin="96,104,0,0" TextWrapping="Wrap" Source="{Binding Image}" VerticalAlignment="Top" Width="120"/>
</Grid>
</UserControl>
MainView.xaml
<Window x:Class="DXDockingMVVMTest1.Views.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
xmlns:dxd="http://schemas.devexpress.com/winfx/2008/xaml/docking"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:ViewModels="clr-namespace:DXDockingMVVMTest1.ViewModels"
xmlns:Views="clr-namespace:DXDockingMVVMTest1.Views" Title="Main Window" Height="400" Width="800">
<Window.Resources>
<!--<Views:Conv x:Key="conv"/>-->
<DataTemplate DataType="{x:Type ViewModels:PanelViewModel}">
<Views:PanelView />
</DataTemplate>
<DataTemplate DataType="{x:Type ViewModels:OtherPanelViewModel}">
<Views:OtherPanelView/>
</DataTemplate>
<Style TargetType="dxd:DocumentPanel">
<Setter Property="Caption" Value="{Binding Caption}" />
<Setter Property="Views:Helper.Name" Value="{Binding Caption}"/>
<Setter Property="AllowFloat" Value="{Binding CanFloat}"/>
</Style>
</Window.Resources>
<dxb:BarManager>
<dxb:BarManager.Categories>
<dxb:BarManagerCategory Name="File" />
</dxb:BarManager.Categories>
<dxb:BarManager.Items>
<dxb:BarButtonItem Name="bNew" CategoryName="File" Content="Add Panel" KeyGesture="Ctrl+N" Hint="" Command="{Binding AddPanelCommand}"/>
<dxb:BarButtonItem Name="bOpen" CategoryName="File" Content="Add Other Panel" KeyGesture="Ctrl+O" Hint="Open" Command="{Binding AddOtherPanelCommand}"/>
<dxb:BarButtonItem Name="bSave" CategoryName="File" Content="Save" KeyGesture="Ctrl+S" Hint="Save Document" ItemClick="OnSaveLayout" />
<dxb:BarButtonItem Name="bExit" CategoryName="File" Content="Restore" KeyGesture="Ctrl+X" ItemClick="OnRestoreLayout"/>
</dxb:BarManager.Items>
<dxb:BarManager.Bars>
<dxb:Bar Caption="Panel1Bar" x:Name="Bar1" UseWholeRow="True" ShowDragWidget="False" AllowQuickCustomization="False">
<dxb:Bar.DockInfo>
<dxb:BarDockInfo ContainerName="panel1DockControl" />
</dxb:Bar.DockInfo>
<dxb:Bar.ItemLinks>
<dxb:BarButtonItemLink BarItemName="bNew" />
<dxb:BarButtonItemLink BarItemName="bOpen" />
<dxb:BarButtonItemLink BarItemName="bSave" />
<dxb:BarButtonItemLink BarItemName="bExit" />
</dxb:Bar.ItemLinks>
</dxb:Bar>
<dxb:Bar Caption="Panel2Bar" x:Name="Bar2" UseWholeRow="True" ShowDragWidget="False" AllowQuickCustomization="False">
<dxb:Bar.DockInfo>
<dxb:BarDockInfo ContainerName="{x:Null}" />
</dxb:Bar.DockInfo>
<dxb:Bar.ItemLinks>
<dxb:BarButtonItemLink BarItemName="bNew" />
<dxb:BarItemLinkSeparator/>
<dxb:BarButtonItemLink BarItemName="bOpen" />
<dxb:BarItemLinkSeparator/>
<dxb:BarButtonItemLink BarItemName="bSave" />
<dxb:BarItemLinkSeparator/>
<dxb:BarButtonItemLink BarItemName="bExit" />
</dxb:Bar.ItemLinks>
</dxb:Bar>
</dxb:BarManager.Bars>
<DockPanel>
<dxb:BarContainerControl Name="Top_Container" DockPanel.Dock="Top"/>
<dxd:DockLayoutManager Name="dockLayoutManager1" ItemsSource="{Binding WidgetList}" FloatingMode="Desktop"
dx:WorkspaceManager.IsEnabled="True"
dxd:RestoreLayoutOptions.RemoveOldPanels="True"
dxd:RestoreLayoutOptions.AddNewPanels="True"
BeforeItemAdded="dockLayoutManager1_BeforeItemAdded" >
<dxd:LayoutGroup x:Name="group">
<dxd:LayoutPanel Visibility="Collapsed" />
<dxd:DocumentGroup x:Name="PanelHost" DestroyOnClosingChildren="False">
</dxd:DocumentGroup>
</dxd:LayoutGroup>
<!--<dxd:DockLayoutManager.ContextMenuCustomizations>
<dxb:AddBarItemLinkAction>
<dxb:BarItemLinkSeparator />
</dxb:AddBarItemLinkAction>
<dxb:BarButtonItem Name="bAbout" CategoryName="Help" Content="About" />
</dxd:DockLayoutManager.ContextMenuCustomizations>
<dxd:DockLayoutManager.ItemSelectorMenuCustomizations>
<dxb:AddBarItemLinkAction>
<dxb:BarItemLinkSeparator />
</dxb:AddBarItemLinkAction>
<dxb:BarButtonItem Name="bHome" CategoryName="Help" Content="AAA" />
</dxd:DockLayoutManager.ItemSelectorMenuCustomizations>-->
</dxd:DockLayoutManager>
</DockPanel>
</dxb:BarManager>
</Window>
Image cannot resize as its height and width is fixed. Remove Height and width of the image.
<Grid>
<Image HorizontalAlignment="Left" Margin="96,104,0,0" Source="{Binding Image}" VerticalAlignment="Top" />
</Grid>
And also remove TextWrapping="Wrap" from image tag. TextWrapping is not a property of image control
try this code:
<Grid> <Image HorizontalAlignment="Left" Source="{Binding Image}" VerticalAlignment="Top" HorizontalAlignment="Left" /> </Grid>

Merged dictionaries

One more easy one.
Resources.xaml contains:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DataTemplate DataType="TestInstanceViewModel" x:Name="TestInstanceViewModelTemplate">
<StackPanel Orientation="Vertical">
<Button Command="{Binding Path=StartCommand}" Content="Start"/>
<Button Command="{Binding Path=StopCommand}" Content="Stop"/>
<TextBlock Text="{Binding Path=Status}"/>
</StackPanel>
</DataTemplate>
Window contains:
<Window x:Class="TestClientMainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Testing client" Height="350" Width="525"
DataContext="{StaticResource ResourceKey=TheViewModel}" Background="#FFD4BFBF">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<StackPanel HorizontalAlignment="Stretch" Name="stackPanel1" VerticalAlignment="Stretch">
<ToolBar Height="26" Name="toolBar1">
<ItemsControl>
<Button Command="{Binding Path=CreateNewTestCommand}">Add new Test</Button>
</ItemsControl>
</ToolBar>
<ListBox ItemsSource="{Binding Path=TestInstances}" ItemTemplate="{StaticResource TestInstanceViewModelTemplate}" Name="listBox1" VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" MinHeight="{Binding ElementName=stackPanel1, Path=Height}" Height="274" />
</StackPanel>
</Grid>
Then there's a list box where I try:
ItemTemplate="{StaticResource TestInstanceViewModelTemplate}"
This doesn't work. What's the logic behind accessing the resource which I've added to the merged dictionaries?
Thanks
Edited:
Try <DataTemplate DataType="TestInstanceViewModel" x:Key="TestInstanceViewModelTemplate">

Resources