我正在研究我的第一个WP7应用程序,这个问题让我头疼。如何将SelectedItem(从ListBox)绑定到变量?
我有这样的
<ListBox Grid.Row="1" ItemsSource="{Binding MyItemList}" SelectedItem="{Binding MySelectedItem}">
<ListBox.ItemTemplate>
<DataTemplate >
<StackPanel>
<TextBlock Text="{Binding Name}" FontSize="35" />
<TextBlock Text="{Binding Details}" FontSize="15"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
绑定的ItemsSource工作正常定义一个列表框,但在选择项目时,MySelectedItem-属性不会得到更新。这个函数没有实现(就像在WPF中)还是我只是在做一些事情? :-)
很酷,谢谢! – 2010-11-12 20:18:27
我无法在WP7项目上使用此工作。任何人都可以验证这是否可以在Windows Phone 7上运行? – SondreB 2011-01-12 09:36:01
我想知道,应该如何工作,因为ListBox的SelectedItems属性是只读属性。它假设抛出一个异常,如“不能设置只读属性System.Windows.Controls.ListBox.SelectedItems”。“ – derSteve 2012-05-21 19:27:58