WPF下Itemscontrol分组 样式

简介: 原文 WPF下Itemscontrol分组 样式     ...

原文 WPF下Itemscontrol分组 样式

   

 <ItemsControl   Grid.Row="1" DataContext="{Binding Layouts}" ItemsSource="{Binding }">
            <ItemsControl.GroupStyle>
                <GroupStyle >
                    <GroupStyle.ContainerStyle >
                        <Style TargetType="{x:Type GroupItem}" >
                            <Setter Property="Margin" Value="0,0,0,10"/>
                            <Setter Property="Template" >
                                <Setter.Value >
                                    <ControlTemplate TargetType="{x:Type GroupItem}">
                                        <Border BorderBrush="Gray"  BorderThickness="1" Margin="5,6,5,1">
                                        <StackPanel  >
                                            <ContentPresenter />
                                            <Border >
                                                 <ItemsPresenter />
                                            </Border>
                                        </StackPanel>
                                        </Border>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                        <GroupStyle.HeaderTemplate >
                        <DataTemplate >
                            <TextBlock Name="txtgroup"  FontSize="13" Foreground="#262679" Text="基本布局"/>
                            <DataTemplate.Triggers >
                                <DataTrigger Binding="{Binding Path=Name}" Value="Increase">
                                    <Setter TargetName="txtgroup" Property="Text" Value="增强布局" />
                                </DataTrigger>
                            </DataTemplate.Triggers>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                </GroupStyle>
            </ItemsControl.GroupStyle>
            <ItemsControl.ItemTemplate >
                <DataTemplate >
                    <Button  Command="{Binding SelectedStyleCommand}" CommandParameter="{Binding Tag}" Background="{Binding Img}"
                                 Width="120" Height="80" Margin="10,10,0,10">
                            <Button.Template >
                                <ControlTemplate TargetType="{x:Type Button}">
                                <Border Name="bd001" CornerRadius="8" Background="{TemplateBinding Background}"  BorderBrush="LightGray" BorderThickness="2">
                                        <ContentPresenter Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" />
                                    </Border>
                                    <ControlTemplate.Triggers >
                                        <Trigger Property="IsMouseOver" Value="True">
                                            <Setter Property="Opacity" Value="0.85" TargetName="bd001"/>
                                            <Setter Property="BorderBrush" Value="Red" TargetName="bd001"/>
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Button.Template>
                        </Button>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
            <ItemsControl.ItemsPanel >
                <ItemsPanelTemplate >
                    <UniformGrid Rows="2" Columns="4"/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <!--<ItemsControl.ItemContainerStyle >
                <Style TargetType="{x:Type ListBoxItem}">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                    <Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}" />
                    <Style.Triggers>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSelected" Value="True" />
                                <Condition Property="IsMouseOver" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter Property="Background" Value="Red"   />
                        </MultiTrigger>
                        <Trigger Property="IsFocused" Value="True">
                            <Setter Property="Background" Value="Green"  />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </ItemsControl.ItemContainerStyle>-->
        </ItemsControl>

 

目录
相关文章
|
2月前
|
C# 容器
浅谈WPF之UniformGrid和ItemsControl
在日常开发中,有些布局非常具有规律性,比如相同的列宽,行高,均匀的排列等,为了简化开发,WPF提供了UniformGrid布局和ItemsControl容器,本文以一个简单的小例子,简述,如何在WPF开发中应用UniformGrid和ItemsControl实现均匀的布局,仅供学习分享使用,如有不足之处,还请指正。
140 0
|
11月前
|
C#
WPF疑难问题之Treeview中HierarchicalDataTemplate多级样式
WPF疑难问题之Treeview中HierarchicalDataTemplate多级样式
227 0
|
11月前
WPF-布局样式练习-Day02-聊天气泡
WPF-布局样式练习-Day02-聊天气泡
167 1
|
2月前
|
C#
浅谈WPF之样式与资源
WPF通过样式,不仅可以方便的设置控件元素的展示方式,给用户呈现多样化的体验,还简化配置,避免重复设置元素的属性,以达到节约成本,提高工作效率的目的,样式也是资源的一种表现形式。本文以一个简单的小例子,简述如何设置WPF的样式以及资源的应用,仅供学习分享使用,如有不足之处,还请指正。
70 0
|
11月前
|
C#
WPF-Binding问题-模板样式使用Binding TemplatedParent与TemplateBinding区别
WPF-Binding问题-模板样式使用Binding TemplatedParent与TemplateBinding区别
128 0
|
11月前
WPF-样式问题-处理ListBox、ListView子项内容全填充问题
WPF-样式问题-处理ListBox、ListView子项内容全填充问题
150 0
|
11月前
|
C#
WPF-布局样式练习-Day01
WPF-布局样式练习-Day01
96 0
|
11月前
WPF-样式问题-ListBox或ListView中子项全填充去除边线问题
WPF-样式问题-ListBox或ListView中子项全填充去除边线问题
94 0
|
12月前
|
C#
WPF属性---重复样式和触发器
WPF属性---重复样式和触发器
91 0
|
前端开发 C#
wpf引用样式
wpf引用样式
105 0