【问题标题】:Template property of type ControlTemplate accepts both 'DataTemplate & ControlTemplate' in style?ControlTemplate 类型的模板属性在样式上同时接受“DataTemplate 和 ControlTemplate”吗?
【发布时间】:2012-05-17 07:35:03
【问题描述】:

为什么我们可以在下面的标记中将DataTemplateControlTemplate 分配给Template 类型的ControlTemplate 属性:-

<Style TargetType="ListBox">
    <Setter Property="Template">
        <Setter.Value>
            <!--
            Visual Studio Intellisense shows
            both ControlTemplate and 
            DataTemplate here.
            -->
        </Setter.Value>
    </Setter>
</Style>

【问题讨论】:

    标签: wpf silverlight-4.0 datatemplate controltemplate


    【解决方案1】:

    我认为答案只是 Intellisense 不够智能(实际上对我而言 VS2010 它显示任何 XAML 都是有效的,而不仅仅是 ControlTemplate 和 DataTemplate)。 documentation on ListBox 表明实际上只有 ControlTemplate 是有效的。如果您将模板声明为 ListBox 的直接子代,而不是 Style,则可以确认这一点:

    <ListBox>
        <ListBox.Template>
            <!-- Intellisense lists only ControlTemplate here -->
        </ListBox.Template>
    </ListBox>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-09
      • 1970-01-01
      • 2014-05-23
      • 1970-01-01
      • 2015-10-07
      • 1970-01-01
      • 2010-12-17
      相关资源
      最近更新 更多