사용자 지정 다중 값 콤보 상자를 만들려고합니다. 기본적으로 콤보 상자에 체크 박스가있는 항목이 있습니다. 전체 컨트롤을 완전히 바인딩 할 수 있도록하기 때문에 언제든지 다시 사용할 수 있습니다.WPF : 사용자 지정 종속성 속성에 대한 친척 소스 데이터 바인딩
여기 그러나, XAML
<ComboBox x:Class="WpfExtensions.Controls.MultiSelectComboBox"
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"
xmlns:local="clr-namespace:WpfExtensions.Controls"
mc:Ignorable="d" d:DesignHeight="23" d:DesignWidth="150">
<ComboBox.Resources>
<local:CheckBoxConverter x:Key="CheckBoxConverter" />
</ComboBox.Resources>
<ComboBox.ItemTemplateSelector>
<local:MultiSelectBoxTemplateSelector>
<local:MultiSelectBoxTemplateSelector.SelectedItemsTemplate>
<DataTemplate>
<TextBlock Text="{Binding Source={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MultiSelectComboBox}}, Path=SelectedItems, Converter={StaticResource CheckBoxConverter}}" />
</DataTemplate>
</local:MultiSelectBoxTemplateSelector.SelectedItemsTemplate>
<local:MultiSelectBoxTemplateSelector.MultiSelectItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding}" HorizontalAlignment="Stretch"
Checked="CheckBox_Checked" Unchecked="CheckBox_Checked" Indeterminate="CheckBox_Checked" Click="CheckBox_Checked" />
</DataTemplate>
</local:MultiSelectBoxTemplateSelector.MultiSelectItemTemplate>
</local:MultiSelectBoxTemplateSelector>
</ComboBox.ItemTemplateSelector>
</ComboBox>
그리고 사용자 지정 속성 "selectedItems를"나는이 프로젝트를 테스트 할 때 이제 RelativeSource는 컨트롤 자체를 향해 제대로 해결
public static readonly DependencyProperty SelectedItemsProperty = DependencyProperty.Register("SelectedItems", typeof(IList), typeof(MultiSelectComboBox));
[Bindable(true)]
public IList SelectedItems
{
get
{
return (IList)GetValue(SelectedItemsProperty);
}
private set
{
SetValue(SelectedItemsProperty, value);
}
}
를위한 뒤에있는 코드입니다 ReloadSource 개체에 해당 경로가 없다는 디버거가 나와서 "SelectedItems"경로의 바인딩이 실패합니다.
바인딩이 엉망이거나 완전히 논리적 오류가 발생 했습니까?
당신은 원본이 아닌 상대 소스를 설정하는, 즉 고칠 변화는 무엇입니까? RelativeSource = {...} – ndonohoe