Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 在DataTemplate内部时绑定控件_Wpf_Wpf Controls - Fatal编程技术网

Wpf 在DataTemplate内部时绑定控件

Wpf 在DataTemplate内部时绑定控件,wpf,wpf-controls,Wpf,Wpf Controls,我正在尝试将一个组合框的字体系列绑定到另一个组合框的字体系列。它工作得很好,直到我将一个数据模板放入我试图从中提取的组合框中。请参阅下面的代码: <Window Height="350" x:Class="MainWindow" Width="525" FontFamily="Palatino Linotype" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.co

我正在尝试将一个组合框的字体系列绑定到另一个组合框的字体系列。它工作得很好,直到我将一个数据模板放入我试图从中提取的组合框中。请参阅下面的代码:

<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,但我不知道如何在这种情况下使用它。

数据模板有一个
VisualTree
属性,您可以使用它来查询其内容,但是,在应用模板之前,内容不存在。

您的SS0组合框上似乎缺少一个
ItemsSource
。您无法访问SS1,请绑定到SS0组合框。