我正在构建一个 Windows 商店应用程序,由于 UI 问题,我必须在组合框中实现复选框。我遇到了以下问题:我想在 "Combobox with Checkbox" 中显示选中的项目。我想做什么:http: //blogs.microsoft.co.il/blogs/justguy/image_2827F1EB.png
<ComboBox x:Name="cb2"
DropDownOpened="cb2_DropDownOpened_1"
DropDownClosed="cb2_DropDownClosed_1"
SelectionChanged="cb2_SelectionChanged_1"
Width="310"
ItemsSource="{Binding Members}"
DisplayMemberPath="{Binding Name}"
Height="50" BorderBrush="#FF0A2562"
Tag="{Binding index}"
>
<ComboBox.ItemTemplate>
<DataTemplate>
<CheckBox
Background="Black"
BorderBrush="Black"
Tag="{RelativeSource TemplatedParent}"
Content="{Binding Name}"
IsChecked="{Binding Path=IsSelected,Mode=OneWay}"
Unchecked="CheckBox_Unchecked_1"
Click="CheckBox_Click"
/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
代码背后:
private void CheckBox_Click(object sender, RoutedEventArgs e)
{
CheckBox chk = (CheckBox)sender;
string k =(string) chk.Content;
chkstr.Add(k);
}
private void CheckBox_Unchecked_1(object sender, RoutedEventArgs e)
{
CheckBox chk = (CheckBox)sender;
string k = (string)chk.Content;
chkstr.Remove(k);
// vl.selectedmembers.Remove(key);
}