我不确定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。那么对于一个控制,有多少模板儿子和孙子?我们可以在图表中列举所有这些和关系吗?
答案 0 :(得分:0)
我在下面解释了属性的名称与类型之间的区别:
<ComboBox>
<ComboBox.ItemTemplate>
<!-- Add a DataTemplate here. It determines how the content
of your data item appears. Use it to bind data
fields or format string and etc -->
</ComboBox.ItemTemplate>
<ComboBox.ItemContainerStyle>
<!-- Add a Style here. It determines the appearance of the
element (e.g., ComboBoxItem) that contains the data. Set
Selection behaviour, Background color, etc-->
</ComboBox.ItemContainerStyle>
<ComboBox.Template>
<!-- Add a ControlTemplate here. It contains the tree of
elements that define the desired look. Of course, most of
the time, you do not set this property and use the default
value. Use it for example to change the shape of the ToggleButton.-->
</ComboBox.Template>
<ComboBox.ItemsPanel>
<!-- Add an ItemsPanelTemplate here. Use it to determine the
the panel that the ItemsPresenter creates for the Items.
You can change the orientation of the ComboBoxItems here .-->
</ComboBox.ItemsPanel>
</ComboBox>
希望它有所帮助。