I am trying to follow the MVVM pattern outlined here: http://msdn.microsoft.com/en-us/magazine/dd419663.aspx#id0090097 I have this in MainWindowResources.xaml:
<DataTemplate DataType="{x:Type vm:VendorsViewModel}"> <vw:Vendors/> <--- I get a "Can't put a page in a style" error in blend with this </DataTemplate>
and I got this in MainWindow.xaml
<Window.Resources> <ResourceDictionary Source="MainWindowResources.xaml"/> </Window.Resources>
The mainWindow.xaml file contains a menu on the left and a page holder on the right. Can I apply dataTemplate to <Page> ? Or should it be <UserControl> ? Be that as it may, nothing is tied to data, here is what I have on the page to which I want to apply a view model:
<Custom:DataGrid Margin="0,30,0,0" d:LayoutOverrides="Width" ItemsSource="{Binding Path=AllVendors, Mode=Default}" > <Custom:DataGrid.Columns> <Custom:DataGridTextColumn Header="Company Name" Binding="{Binding Path=Name}" /> </Custom:DataGrid.Columns> </Custom:DataGrid>
source share