我正在構建一個Windows應用商店應用程序,並且由於UI問題,我必須在combobox中實現複選框。我被困在以下問題:我想在「組合框與複選框「。 我想做什麼: 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);
}
感謝Reply.But如何在Combobox中顯示用逗號分隔的選中項目。喜歡這個圖片:[link](http://blogs.microsoft.co.il/blogs/justguy/image_2827F1EB.png) – 2013-02-27 05:20:01