ฉันมี WPF ของผู้ใช้ควบคุมซึ่งมัน ListBox
ที่บรรจุ 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>
ฉันกำลังใช้ตัวควบคุมนี้อยู่ที่สถานที่แห่งใหม่:
<GroupBox Header="{Binding ElementName=Root, Path=Header, FallbackValue=Header}">
<user:CheckedListBox ItemsSource="{Binding ElementName=Root, Path=Companies}" />
</GroupBox>
ตอนนี้สถานที่ที่ Companies
ทรัพย์สินเป็น ObservableCollection<CheckedListBoxItem<Company>>
.
CheckedListBoxItem
คือชั้นเรียนกับ bool IsChecked
ทรัพย์สินและทั่วไป T Item
พื้นที่ของเขา
ตอนนี้ T Item
จะเป็นอะไรก็ได้ ตอนนี้ฉันมีทรัพย์สินตั้งค่าเป็น Content
ของ CheckBox
ฉันคิดว่าเธอ....แต่เกือบทุกครั้งนี้ส่งผลให้เกิดบางอย่างยังกำกวมเนื่องจาเหมือน AC.CodA.Scripting.Shared.Company
.
มีสักทางเพื่อตั้งค่า CheckBox
Content
ข้างนอกของผู้ใช้ควบคุม? บางอย่างเหมือนกับ CheckBoxContent
:
<GroupBox Header="{Binding ElementName=Root, Path=Header, FallbackValue=Header}">
<user:CheckedListBox ItemsSource="{Binding ElementName=Root, Path=Companies}" CheckBoxContent="{Binding Item.Name}" />
</GroupBox>
และข้างในของวัตถุนี้:
<CheckBox IsChecked="{Binding IsChecked}"
Content="{Binding CheckBoxContent}">
</CheckBox>
CheckBoxContent
เมื่อใช้CheckedListBox
? ไปเรียนCompany
สำหรับตัวอย่างกับเป็นทรัพย์สินName
. ฉันพยายามต่อไปนี้แต่เนื้อหาภายว่าง:<user:CheckedListBox ItemsSource="{Binding ElementName=Root, Path=Companies}" CheckBoxContent="{Binding Name}" />
.