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

WPF ListView ListBox 常用的样式记录

时间:2017-07-19 17:47:36      阅读:956      评论:0      收藏:0      [点我收藏+]

标签:ane   horizon   style   target   resource   column   add   nes   width   

ListView:

<ListView x:Name="lvBlockedApps"
                        ItemsSource="{Binding BlockedAppsCollecion}">
                        <ListView.Style>
                            <Style TargetType="ListView">
                                <Setter Property="VerticalAlignment" Value="Top"></Setter>
                                <Setter Property="HorizontalAlignment" Value="Stretch"></Setter>
                                <Setter Property="SelectionMode" Value="Single"></Setter>

                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type ListView}">
                                            <ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Auto" HorizontalAlignment="Stretch">
                                                <ItemsPresenter/>
                                            </ScrollViewer>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>

                            </Style>
                        </ListView.Style>
                        <ListView.ItemContainerStyle>
                            <Style TargetType="{x:Type ListViewItem}">
                                <Setter Property="Height" Value="40"></Setter>
                                <Setter Property="Margin" Value="5,2,3,0"></Setter>
                                <Setter Property="BorderBrush" Value="Red"></Setter>
                                <Setter Property="BorderThickness" Value="2"/>
                                <Setter Property="Cursor" Value="Hand"></Setter>
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type ListViewItem}">
                                            <Border x:Name="back" BorderBrush="Green" BorderThickness="0" >
                                                <Grid>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="Auto"></ColumnDefinition>
                                                        <ColumnDefinition Width="*"></ColumnDefinition>
                                                        <ColumnDefinition Width="Auto"></ColumnDefinition>
                                                    </Grid.ColumnDefinitions>
                                                    <Border Grid.Column="0" Width="32" Height="32" CornerRadius="5" Background="#FF83CAD1" Margin="5,0,0,0">
                                                        <Border>
                                                            <Border.Background>
                                                                <ImageBrush ImageSource="{Binding AppIcon,Converter={StaticResource ImgPathToImageConverter}}"></ImageBrush>
                                                            </Border.Background>
                                                        </Border>
                                                    </Border>
                                                    <customControl:EnhancedTextBlock Grid.Column="1" Margin="10,0,0,0" FontSize="16" Text="{Binding Name}" />
                                                    <Button Grid.Column="2"
                                                        x:Name="btnUnblock"
                                                        Width="60" Height="23"
                                                        Content="Unblock"
                                                        Padding="0"
                                                        Margin="0,0,8,0"
                                                        Style="{DynamicResource FileDialogButtonStyle}"
                                                        Click="btnUnblock_Click"></Button>
                                                </Grid>
                                            </Border>
                                            <ControlTemplate.Triggers>
                                                <Trigger Property="IsMouseOver" Value="True">
                                                    <Setter TargetName="back" Property="Background" Value="LightGray"></Setter>
                                                </Trigger>
                                                <Trigger Property="IsSelected" Value="True">
                                                    <Setter TargetName="back" Property="Background" Value="Gray"></Setter>
                                                </Trigger>
                                            </ControlTemplate.Triggers>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>

                            </Style>
                        </ListView.ItemContainerStyle>
                    </ListView>

ListBox:
                    <ListBox x:Name="lbPageMenus" ItemsSource="{Binding PageMenus}" SelectionMode="Single">
                        <ListBox.Template>
                            <ControlTemplate TargetType="{x:Type ListBox}">
                                <ItemsPresenter/>
                            </ControlTemplate>
                        </ListBox.Template>
                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapPanel Orientation="Horizontal" IsItemsHost="True"/>
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>
                        <ListBox.ItemContainerStyle>
                            <Style TargetType="ListBoxItem">
                                <Setter Property="Margin" Value="0,0,50,0"></Setter>
                                <Setter Property="Cursor" Value="Hand"></Setter>
                                <Setter Property="IsSelected" Value="{Binding IsSelected}"></Setter>
                                <Setter Property="IsEnabled" Value="{Binding IsEnabled}"></Setter>
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                            <Border x:Name="back" BorderBrush="Transparent" BorderThickness="0,0,0,5"  Width="{Binding Width}" Height="{Binding Height}">
                                                    <TextBlock x:Name="text"
                                                        Text="{Binding DisplayName}"
                                                        VerticalAlignment="Center"
                                                        HorizontalAlignment="Center"
                                                        FontSize="22"
                                                        Foreground="White"></TextBlock>
                                                </Border>
                                            <ControlTemplate.Triggers>
                                                <Trigger Property="IsSelected" Value="True">
                                                    <Setter TargetName="text" Property="Foreground" Value="#FF47F5F5"></Setter>
                                                    <Setter TargetName="back" Property="BorderBrush" Value="#FF47F5F5"></Setter>
                                                </Trigger>
                                                <Trigger Property="IsEnabled" Value="False">
                                                    <Setter TargetName="text" Property="Foreground" Value="#FF89D7D4"></Setter>
                                                    <Setter TargetName="back" Property="BorderBrush" Value="Transparent"></Setter>
                                                </Trigger>
                                            </ControlTemplate.Triggers>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </ListBox.ItemContainerStyle>
                    </ListBox>

 

WPF ListView ListBox 常用的样式记录

标签:ane   horizon   style   target   resource   column   add   nes   width   

原文地址:http://www.cnblogs.com/lopengye/p/7206675.html

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