【问题标题】:Custom Panel Providing Both Datatemplate And non-Datatemplate提供数据模板和非数据模板的自定义面板
【发布时间】:2015-10-04 13:45:27
【问题描述】:

我想创建一个面板,我可以像下面的示例一样使用它。

示例 1:

<custom:CustomPanel ItemsSource="{Binding DataSource}">
    <custom:CustomPanel.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding}" />
        </DataTemplate>
    </custom:CustomPanel.ItemTemplate>
</custom:CustomPanel>

示例 2:

<custom:CustomPanel>
    <TextBlock Text="text1" />
    <TextBlock Text="text2" />
    <TextBlock Text="text3" />
</custom:CustomPanel>

我实现了第一个,现在我可以正常使用它了。我通过从 ItemsControl 继承有关类来提供它,如下所示。

class CustomPanel : ItemsControl{
    ...
}

我如何提供第二个示例工作?

【问题讨论】:

  • 当您从 ItemsControl 派生时,第二个示例也可以开箱即用。

标签: c# xaml winrt-xaml custom-controls itemscontrol


【解决方案1】:

对于第二个,您需要从 ContentControl 继承。

【讨论】:

  • 对不起,我的错。 ContentControl 只能有一个直接子级。
猜你喜欢
  • 2013-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-17
  • 2022-07-22
  • 2015-10-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多