2017-03-02 8 views
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があります。コントロールのために、テンプレートの息子と孫の数はいくつですか?私たちはそれらをすべてと関係をチャートで列挙できますか?

<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> 

はそれが役に立てば幸い:

答えて

0

は私が名の違い次のプロパティとその種類のを説明します。

+0

これはコンボボックスのためです。一般的なコントロールでは、それがボタンの場合、それは同じパターンを持っていますか? – Bigeyes

+0

いいえ、Buttonには '' 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

+0

各コントロールには独自のパターンがあります。これらをどのように記憶できますか? – Bigeyes