提出ItemsControl

时间:2015-05-08 16:11:25

标签: wpf xaml contentpresenter

简单的问题!

我想在扩展器和包含文本框的网格中提供一个itemscontrol。我想多次这样做,所以我将它包装在ControlTemplate中。

    <ControlTemplate x:Key="ArrayPresenter">
    <Expander Template="{StaticResource ArrayTemplate}">
        <Grid>
            <ContentPresenter/>
            <TextBlock FontWeight="Bold" Text="Empty" Margin="3" HorizontalAlignment="Center" Foreground="#66C9C9C9" FontSize="15" Visibility="{quickConverter:Binding '$P.Count == 0 ? Visibility.Visible : Visibility.Collapsed', P={Binding Array}}" />
        </Grid>
    </Expander>
</ControlTemplate>

这就是我想要呈现的内容。不幸的是,只要将一个项目添加到itemscontrol,就没有任何反应,并且它不会显示新项目!

<ContentControl Template="{StaticResource ArrayPresenter}">
        <ItemsControl Style="{StaticResource ArrayItemsStyle}" Margin="5" ItemTemplate="{StaticResource StructureFieldTemplate}"/>
    </ContentControl>

1 个答案:

答案 0 :(得分:1)

如评论中所述,您需要定位ControlTemplate

的类型
<ControlTemplate ... TargetType="{x:Type ContentControl}">

没有ControlTemplate目标System.Windows.Controls.Control类型且没有Content来呈现,因此ContentPresenter不知道要显示什么。

相关问题