我目前正在WinRT中編寫一個應用程序,我需要從列表視圖中的選定項傳回一個id給我的viewmodel。我的listview有一個Observable集合作爲一個itemsource,因此listview中的每個項目都會有一個不同的id。將數據從選定的項目傳遞到WinRT中的viewmodel
我的XAML代碼類似於這樣
<ListView Grid.Column="0" ItemsSource="{Binding VacationOverviewDisplay}" >
<WinRtBehaviors:Interaction.Behaviors>
<Win8nl_Behavior:EventToCommandBehavior Event="SelectionChanged"
Command="DetailsCommand"
CommandParameter="{Binding Path=DontKnow, Mode=TwoWay}"/>
</WinRtBehaviors:Interaction.Behaviors>
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" >
<StackPanel Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontFamily="Segoe UI" Text="{Binding VacationStart, Converter={StaticResource StringFormatConverter}, ConverterParameter='{}{0:dd MMM yyyy}' }" Margin="20,0,0,0"></TextBlock>
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontFamily="Segoe UI" Text="{Binding VacationEnd, Converter={StaticResource StringFormatConverter}, ConverterParameter='{}{0:dd MMM yyyy}' }" Margin="20,0,0,0"></TextBlock>
<TextBlock x:Name="id" VerticalAlignment="Center" FontWeight="Bold" FontFamily="Segoe UI" Text="{Binding VacationRequestId}" Margin="20,0,0,0"></TextBlock>
</StackPanel>
<TextBlock Text="{Binding StatusView}" Margin="50,0,0,0"></TextBlock>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Title: " Margin="50,0,0,0"></TextBlock>
<TextBlock FontStyle="Italic" Text="{Binding VacationCommentUser}" Margin="5,0,0,0"></TextBlock>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
我使用WinRTBehaviors模仿EventToCommand行爲,但我不知道我應該如何在我的列表視圖得到的項目的某個參數回到我的視圖模型。爲Mvvm我使用MvvmLight。
謝謝你這個問題idd,bi不笨,但我想我現在不會忘記:) – Landvis 2013-02-28 09:44:08