가 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}" />
.