• WPF ListView ListBox 常用的样式记录


    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>
  • 相关阅读:
    hdu 2553 N皇后问题(dfs)
    hdu 1043 Eight(双向bfs)
    牛人的ACM经验 (转)
    康托和逆康托展开(转)
    hiho Mission Impossible 6(模拟 未提交验证。。)
    数组越界也可以这么巧~~~
    poj 1679 The Unique MST(次小生成树)
    zoj 3204 Connect them(最小生成树)
    hdu 4463 Outlets(最小生成树)
    廖雪峰Java1-2程序基础-8字符和字符串
  • 原文地址:https://www.cnblogs.com/lopengye/p/7206675.html
Copyright © 2020-2023  润新知