some free cycles. I am also working of a Windows 7 phone app and will share a few things that apply to Silverlight in general.
The first is working with SL4 Commanding and MVVM in a DataTemplated UI.Here is my template:
<UserControl.Resources>
local:StockServiceVM x:Key="vm"/>
<DataTemplate x:Key="QuoteTemplate" >
<StackPanel Name="QuoteContainer" Orientation="Vertical" Width="290" Background="Gray">
<StackPanel Orientation="Horizontal">
<TextBlock Foreground="White" Text="{Binding Path= Symbol, Mode=OneWay}" Width="70"/>
<TextBlock Foreground="White" Width="78" Text="{Binding Path=Time}"/>
<TextBlock Foreground="White" Width="80" Text="{Binding Path=Volume}"/>
<Button x:Name="this" Width="20" HorizontalContentAlignment="Right" Content="+"
Command="{Binding Path=ExpandCommand,Source={StaticResource vm}}"
CommandParameter="{Binding ElementName= this}"></Button>
</StackPanel>
</DataTemplate>
</UserControl.Resources>
I am using Commanding to fire the Button click event into my viewmodel and notice the use of the Source property in the Binding definition:
Command="{Binding Path=ExpandCommand,Source={StaticResource vm}}"
If this is omitted my Binding did not work and thus my ViewModel never received the event.
0 comments:
Post a Comment