1
我不确定wpf控件的分层模板。例如,对于组合框。控件的分层模板
<ComboBox ItemsSource="{Binding .}">
<ComboBox.ItemTemplate>
<DataTemplate>
<Border HorizontalAlignment="Stretch">
<Border.Style>
<Style TargetType="Border">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ComboBoxItem}, Path=DataContext.IsSelected}" Value="True">
<Setter Property="Background" Value="LightGreen"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<StackPanel HorizontalAlignment="Stretch">
<TextBlock Text="{Binding Name}"/>
<TextBlock Text="{Binding Email}">
</TextBlock>
</StackPanel>
</Border>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
它可能有控制模板类似,但我不知道。
combox有一个模板儿子ItemTemplate和一个孙子DateTemplate。因此,为了控制,有多少模板儿子和孙子?我们可以枚举它们和图表中的关系吗?
所以这对于组合框。在一般控制中,如果它是一个按钮,它是否具有相同的模式? – Bigeyes
不,一个按钮没有“ItemTemplate”,“ItemContainerStyle”和“ItemsPanel”。这些特定于[''ItemsControl''](https://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol(v = vs.110).aspx)和其他控件派生自它,比如''ListBox'',''TreeView''等''Button''具有''ControlTemplate''类型的'''Template''属性。实际上,它不需要这些属性。 – Ron
所以每个控件都有自己的模式。我怎样才能记住这些? – Bigeyes