码迷,mamicode.com
首页 > Windows程序 > 详细

WPF下Itemscontrol分组 样式

时间:2018-05-17 12:00:12      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:ret   seo   opacity   class   nts   ems   radius   style   chm   

原文 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分组 样式

标签:ret   seo   opacity   class   nts   ems   radius   style   chm   

原文地址:https://www.cnblogs.com/lonelyxmas/p/9048956.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!