我正在尝试将组合框的字体系列绑定到另一个组合框的字体系列。它工作正常,直到我将数据模板放在我试图从中提取的组合框中。请看下面的代码:
<Window Height="350" x:Class="MainWindow" Width="525" FontFamily="Palatino Linotype" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<StackPanel Grid.Column="1" Name="ComboBoxStackPanel" Margin="6" VerticalAlignment="Top">
<ComboBox FontFamily="Wingdings" Name="SS0">
<ComboBox.ItemTemplate>
<DataTemplate x:Name="SSD">
<Grid>
<Grid.RowDefinitions>
<RowDefinition SharedSizeGroup="Row" Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Name="SS1" FontSize="14" Text="{Binding}" FontFamily="Wingdings"/>
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<ComboBox FontFamily="{Binding FontFamily, ElementName=SS1}" SelectedIndex="1">
Test
<ComboBoxItem FontStyle="Normal" FontWeight="Normal">Regular</ComboBoxItem>
<ComboBoxItem FontStyle="Italic" FontWeight="Normal">Italic</ComboBoxItem>
<ComboBoxItem FontStyle="Normal" FontWeight="Bold">Bold</ComboBoxItem>
<ComboBoxItem FontStyle="Italic" FontWeight="Bold">Bold Italic</ComboBoxItem>
</ComboBox>
</StackPanel>
</Window>
我可以很好地访问 SS0,但是当我尝试访问 SS1 时,它会失败。我试过使用RelativeSource,但我很困惑如何在这种情况下使用它。