WPF下Itemscontrol分组 样式

Posted lonelyxmas

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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>

 

以上是关于WPF下Itemscontrol分组 样式的主要内容,如果未能解决你的问题,请参考以下文章

WPF实现QQ群文件列表动画

WrapPanel 作为 ItemsControl 的 ItemPanel

ItemsControl 组合框 selecteditem C# WPF MVVM

WPF效果第一百七十八篇ItemsControl旋转

WPF ItemsControl 取消选中item项,滚动条自动跑到该item顶部的问题

WPF - ItemsControl - 如何找到ItemTemplate中的“CheckBox”项?