麻烦结合LongListSelector.SelectedItem到MVVM财产 [英] Trouble binding LongListSelector.SelectedItem to MVVM property
问题描述
使用Visual Studio 2013和窗口Phone 8的SDK,我不能得到的 LongListSelector
正确的的SelectedItem
属性绑定到MVVM属性
这似乎是一个相同的问题,在其列入在SDK而是作为固定该标记之前该控制存在的错误。 http://silverlight.codeplex.com/workitem/9360
是任何人都经历了这一点,知道一个修复/更新的版本?
我目前使用的背后解决办法
私人无效代码LongListSelector_SelectionChanged (对象发件人,SelectionChangedEventArgs E)
{
LongListSelector S =发件人为LongListSelector;
VAR VM =的DataContext作为ViewModel.MainViewModel;
Debug.Assert的(VM!= NULL);
vm.SelectedLegislator = s.SelectedItem;
}
要获取这是该项目选定的视图模型,我总是用LongListSelector扩展 - 该代码可以在这里找到: https://开头gist.github.com/Depechie/7524630
您需要做的是将它添加到您的LongListSelector的XAML:
<电话:LongListSelector X:名称=列表EXT:LongListSelectorExtension.Command ={结合* YOURVIEWMODELCOMMAND *}/>
在视图模型的命令将收到一份关于LongListSelector您的项目源的对象类型
Using Visual Studio 2013 and the Window Phone 8 SDK I cannot get the SelectedItem
property of the LongListSelector
to properly bind to an MVVM property.
It appears to be an identical issue to a bug that existed in the control prior to its inclusion in the SDK but which is marked as fixed. http://silverlight.codeplex.com/workitem/9360
Is anyone else experiencing this and know of a fix/updated version?
I am currently using a code behind workaround
private void LongListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
LongListSelector s = sender as LongListSelector;
var vm = DataContext as ViewModel.MainViewModel;
Debug.Assert(vm != null);
vm.SelectedLegislator = s.SelectedItem;
}
To get the item that was selected to the ViewModel, I'm always using a LongListSelector Extension - the code can be found here: https://gist.github.com/Depechie/7524630
What you need to do is add it to the XAML of your LongListSelector:
<phone:LongListSelector x:Name="List" ext:LongListSelectorExtension.Command="{Binding *YOURVIEWMODELCOMMAND*}" />
The command on the viewmodel will receive the object type of your item source on the LongListSelector
这篇关于麻烦结合LongListSelector.SelectedItem到MVVM财产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!