ItemsControl的ItemContainerStyle屬性


ItemsControl:ListBox,ComboBox,TreeView

ItemContainerStyle是用來設置每一個集合控件的Item的樣式的屬性(即設置每一個項的樣式)。 

  使用ItemContainerStyle 需要注意,如果集合控件的每一項是通過綁定生成的,則ItemContainerStyle對每一項Item都起作用,如果集合控件的項是通過直接在XAML中添加的,則ItemContainerStyle只對集合控件的第一層Item起作用。
  這個效果容易在TreeView等有層次結構的集合控件中引起誤解。
 
 
例:
<Setter Property="ItemContainerStyle">
            <Setter.Value>
                <Style TargetType="Control">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                    <Setter Property="VerticalContentAlignment" Value="Stretch"/>
                    <Setter Property="Height" Value="42"/>
                </Style>
            </Setter.Value>
        </Setter>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM