【发布时间】:2015-08-04 06:27:02
【问题描述】:
我使用以下代码将多选列表框中的值与 silverlight 中的复选框绑定
<ListBox x:Name="ValListBox" Margin="188,212,136,100" SelectionMode="Multiple">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem}, Path=IsSelected}" Content="{Binding}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我需要使用 c# 获取所选项目的文本吗?
【问题讨论】:
-
如果你想要 ViewModel,你可以通过将 ListBox 的 SelectedItem 绑定到与 ItemsSource Collection 相同类型的属性来获得它。如果你想在 xaml 中使用它,那么你可以绑定 SelectedItem.Content 属性和 ElementName ValListBox
标签: c# wpf xaml silverlight listbox