|
|
I'm at step 10 of the Getting Started, making the changes I think are necessary for WPF instead of Silverlight. However, I'm not sure how exactly to proceed. Here's what I've got:
<Window x:Class="SimpleMvvmWpf1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:SimpleMvvmWpf1"
Title="MainWindow" Height="350" Width="525"
DataContext="{Binding Source={StaticResource Locator}, Path=[ProductListViewModel]}">
<!-- The DataContext attribute was: DataContext="{Binding Source={StaticResource Locator}, Path=[MainPageViewModel]}" -->
<!--<StackPanel>
<TextBlock Text="{Binding Path=BannerText}" FontFamily="Verdana" FontSize="18" FontWeight="Bold" HorizontalAlignment="Center" />
<my:CustomerView />
</StackPanel>-->
<Grid>
<my:ProductListView />
</Grid>
</Window>
The code is from my MainWindow.xaml, but I'm sure this is wrong, I'd appreciate guidance, please.
|
|
Coordinator
Dec 28, 2011 at 1:51 PM
|
You have to bind the ItemsSource of the grid to a property on the ProductListViewModel, for example, Products.
|
|
Coordinator
Dec 28, 2011 at 1:51 PM
|
You have to bind the ItemsSource of the grid to a property on the ProductListViewModel, for example, Products.
|
|
|
|
Thank you for replying. I'm sorry it's taking me so long to get back to you; I'm busy with house maintenance, so timely responses at this point aren't easy to do.
Anyway, here's what I now have, based upon your response. First, I'll show ProductListView.xaml:
<UserControl x:Class="SimpleMvvmWpf1.Views.ProductListView"
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="400" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
DataContext="{Binding Source={StaticResource Locator}, Path=ProductListViewModel}"
>
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="239*" />
</Grid.RowDefinitions>
<Button Content="Load Products" Height="23" HorizontalAlignment="Center" Margin="5" Name="button1" VerticalAlignment="Top" Width="75">
<!-- Add reference to Microsoft.Expression.Interactions.dll, System.Windows.Interactivity.dll -->
<!-- Use mvvmxmlns snippet to add i and ei namespace prefixes -->
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<ei:CallMethodAction
TargetObject="{Binding}"
MethodName="LoadProducts"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<DataGrid AutoGenerateColumns="True" Grid.Row="1" Height="200" HorizontalAlignment="Left" Margin="13,9,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="200" ItemsSource="{Binding Path=Products, Mode=TwoWay}" />
</Grid>
</UserControl>
Next is MainWindow.xaml. I don't think I've done this right, as I've explicitly put a XML namespace into the XAML. Here it is:
<Window x:Class="SimpleMvvmWpf1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:SimpleMvvmWpf1"
Title="MainWindow" Height="350" Width="525"
xmlns:v="clr-namespace:SimpleMvvmWpf1.Views"
DataContext="{Binding Source={StaticResource Locator}, Path=[ProductListViewModel]}">
<!-- The DataContext attribute was: DataContext="{Binding Source={StaticResource Locator}, Path=[MainPageViewModel]}" -->
<!--<StackPanel>
<TextBlock Text="{Binding Path=BannerText}" FontFamily="Verdana" FontSize="18" FontWeight="Bold" HorizontalAlignment="Center" />
<my:CustomerView />
</StackPanel>-->
<Grid>
<!-- <my:ProductListView /> -->
<v:ProductListView />
</Grid>
</Window>
So, have I missed the boat, as far as what Simple MVVM Toolkit is supposed to be all about?
|
|