首页 > 代码库 > WPF ListView ListBox 常用的样式记录
WPF ListView ListBox 常用的样式记录
ListView:
<ListView x:Name="lvBlockedApps" ItemsSource="{Binding BlockedAppsCollecion}"> <ListView.Style> <Style TargetType="ListView"> <Setter Property="VerticalAlignment" Value=http://www.mamicode.com/"Top"></Setter> <Setter Property="HorizontalAlignment" Value=http://www.mamicode.com/"Stretch"></Setter> <Setter Property="SelectionMode" Value=http://www.mamicode.com/"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=http://www.mamicode.com/"40"></Setter> <Setter Property="Margin" Value=http://www.mamicode.com/"5,2,3,0"></Setter> <Setter Property="BorderBrush" Value=http://www.mamicode.com/"Red"></Setter> <Setter Property="BorderThickness" Value=http://www.mamicode.com/"2"/> <Setter Property="Cursor" Value=http://www.mamicode.com/"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=http://www.mamicode.com/"True"> <Setter TargetName="back" Property="Background" Value=http://www.mamicode.com/"LightGray"></Setter> </Trigger> <Trigger Property="IsSelected" Value=http://www.mamicode.com/"True"> <Setter TargetName="back" Property="Background" Value=http://www.mamicode.com/"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=http://www.mamicode.com/"0,0,50,0"></Setter> <Setter Property="Cursor" Value=http://www.mamicode.com/"Hand"></Setter> <Setter Property="IsSelected" Value=http://www.mamicode.com/"{Binding IsSelected}"></Setter> <Setter Property="IsEnabled" Value=http://www.mamicode.com/"{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=http://www.mamicode.com/"True"> <Setter TargetName="text" Property="Foreground" Value=http://www.mamicode.com/"#FF47F5F5"></Setter> <Setter TargetName="back" Property="BorderBrush" Value=http://www.mamicode.com/"#FF47F5F5"></Setter> </Trigger> <Trigger Property="IsEnabled" Value=http://www.mamicode.com/"False"> <Setter TargetName="text" Property="Foreground" Value=http://www.mamicode.com/"#FF89D7D4"></Setter> <Setter TargetName="back" Property="BorderBrush" Value=http://www.mamicode.com/"Transparent"></Setter> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </ListBox.ItemContainerStyle> </ListBox>
WPF ListView ListBox 常用的样式记录
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。