Bir WPF kullanıcı denetimim var ListBox
bu içerir CheckBox
es.
<UserControl x:Class="AC.CodA.WPF.UserControls.CheckedListBox"
x:Name="Root"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:Background="White">
<StackPanel>
<ListBox BorderThickness="0"
ItemsSource="{Binding ElementName=Root, Path=ItemsSource}">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Focusable"
Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<ContentPresenter />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsChecked}"
Content="{Binding Item}">
</CheckBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Separator />
<CheckBox x:Name="DeSelectAll"
Content="Select / deselect all"
Checked="DeSelectAll_Checked"
Unchecked="DeSelectAll_Unchecked" />
</StackPanel>
</UserControl>
Bu kontrolü başka bir yerde kullanıyorum.:
<GroupBox Header="{Binding ElementName=Root, Path=Header, FallbackValue=Header}">
<user:CheckedListBox ItemsSource="{Binding ElementName=Root, Path=Companies}" />
</GroupBox>
Bu mahalde Companies
mülkiyet bir ObservableCollection<CheckedListBoxItem<Company>>
.
CheckedListBoxItem
ile bir sınıftır bool IsChecked
mülkiyet ve jenerik T Item
mülk.
Şimdi, T Item
herhangi bir şey olabilir. Bu noktada bu özellik şu şekilde ayarlandı: Content
of the CheckBox
ancak çoğu zaman bu, aşağıdaki gibi belirsiz bir şeyle sonuçlanır AC.CodA.Scripting.Shared.Company
.
Bir şekilde ayarlamak için CheckBox
Content
kullanıcı kontrolü dışında mı? Böyle bir şeyle CheckBoxContent
:
<GroupBox Header="{Binding ElementName=Root, Path=Header, FallbackValue=Header}">
<user:CheckedListBox ItemsSource="{Binding ElementName=Root, Path=Companies}" CheckBoxContent="{Binding Item.Name}" />
</GroupBox>
ve nesnemin içinde bu:
<CheckBox IsChecked="{Binding IsChecked}"
Content="{Binding CheckBoxContent}">
</CheckBox>
CheckBoxContent
kullanırkenCheckedListBox
? Bir ders alCompany
örneğin bir özellik ileName
. Aşağıdakileri denedim ancak içerik boş:<user:CheckedListBox ItemsSource="{Binding ElementName=Root, Path=Companies}" CheckBoxContent="{Binding Name}" />
.