У меня есть пара комбинированных списков в элементе данных элемента управления. Элемент управления работает нормально, но когда я нажимаю на комбинированный список и показываю опции, я получаю следующую ошибку в выводе отладчика.
Cannot find source for binding with reference 'RelativeSource FindAncestor,
AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''.
BindingExpression:Path=VerticalContentAlignment; DataItem=null; target element is
'ComboBoxItem' (Name=''); target property is 'VerticalContentAlignment' (type
'VerticalAlignment')
Cannot find source for binding with reference 'RelativeSource FindAncestor,
AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''.
BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is
'ComboBoxItem' (Name=''); target property is 'HorizontalContentAlignment' (type
'HorizontalAlignment')
Я посмотрел на подобные проблемы, и добавление следующего xaml к контролю, похоже, исправило проблему для некоторых людей.
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Top" />
</Style>
но я все еще получаю ту же ошибку.Любые идеи, что еще я могу изменить?
Вот мой полный xaml для контроля
<ItemsControl ItemsSource="{Binding AccessControl.Credentials}" HorizontalContentAlignment="Stretch">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid MinWidth="600" HorizontalAlignment="left" Margin="0,0,0,10">
<Grid.ColumnDefinitions >
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Label Grid.Column="0"
Content="{Binding Path=DisplayName}"
Width="200"
Margin="3,3,0,0"/>
<ComboBox Grid.Column="2"
Grid.Row="0"
Name="chkFieldType"
Tag="{Binding Path=ID}"
Width="160"
Margin="19,0,0,0"
SelectionChanged="chkFieldType_SelectionChanged"
DropDownOpened="ComboBox_DropDownOpened"
ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=ItemsControl},
Path=DataContext.AccessControl.TypeOptions}"
SelectedValue="{Binding ValueSourceForViewModel,Mode=TwoWay}">
<ComboBox.Resources>
<Style TargetType="{x:Type ComboBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsChecked, ElementName=chkPool}" Value="false">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="Foreground" Value="#FF000000"/>
<Setter Property="Template" Value="{DynamicResource ComboBoxTemplate}" />
</Style>
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Top" />
</Style>
</ComboBox.Resources>