• wpf listbox 无选中背景,及纵向横向排列完整实例


    建议使用ItemsControl替代,ListBox限制太多

    <
    TabItem Header="我的Tab页" Name="tabItem1"> <TabItem.Resources> <SolidColorBrush x:Key="Item.MouseOver.Background" Color="Transparent"/> <SolidColorBrush x:Key="Item.MouseOver.Border" Color="Transparent"/> <SolidColorBrush x:Key="Item.SelectedInactive.Background" Color="Transparent"/> <SolidColorBrush x:Key="Item.SelectedInactive.Border" Color="Transparent"/> <SolidColorBrush x:Key="Item.SelectedActive.Background" Color="Transparent"/> <SolidColorBrush x:Key="Item.SelectedActive.Border" Color="Transparent"/> <Style x:Key="ListBoxTitleStyle" TargetType="{x:Type ListBoxItem}"> <Setter Property="SnapsToDevicePixels" Value="True"/> <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> <Setter Property="Background" Value="Transparent"/> <Setter Property="BorderBrush" Value="Transparent"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListBoxItem}"> <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true"> <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> </Border> <ControlTemplate.Triggers> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsMouseOver" Value="True"/> </MultiTrigger.Conditions> <Setter Property="Background" TargetName="Bd" Value="{StaticResource Item.MouseOver.Background}"/> <Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource Item.MouseOver.Border}"/> </MultiTrigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="Selector.IsSelectionActive" Value="False"/> <Condition Property="IsSelected" Value="True"/> </MultiTrigger.Conditions> <Setter Property="Background" TargetName="Bd" Value="{StaticResource Item.SelectedInactive.Background}"/> <Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource Item.SelectedInactive.Border}"/> </MultiTrigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="Selector.IsSelectionActive" Value="True"/> <Condition Property="IsSelected" Value="True"/> </MultiTrigger.Conditions> <Setter Property="Background" TargetName="Bd" Value="{StaticResource Item.SelectedActive.Background}"/> <Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource Item.SelectedActive.Border}"/> </MultiTrigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="TextElement.Foreground" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </TabItem.Resources> <ListBox x:Name="lstTypes" ScrollViewer.CanContentScroll="false" HorizontalContentAlignment="Stretch" ItemContainerStyle="{StaticResource ListBoxTitleStyle}" > <ListBox.Template> <ControlTemplate TargetType="{x:Type ListBox}"> <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled"> <StackPanel Orientation="Vertical" IsItemsHost="True" ScrollViewer.CanContentScroll="False" /> </ScrollViewer> </ControlTemplate> </ListBox.Template> <ListBox.ItemTemplate> <DataTemplate> <GroupBox Grid.Row="0" Header="{Binding Path=societyType.name}" Margin="10" Padding="10"> <ListBox x:Name="lstSocieties" ItemsSource="{Binding Path=societies}" BorderThickness="0"> <ListBox.Template> <ControlTemplate TargetType="{x:Type ListBox}"> <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto"> <WrapPanel Orientation="Horizontal" IsItemsHost="True" ScrollViewer.CanContentScroll="True"/> </ScrollViewer> </ControlTemplate> </ListBox.Template> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Vertical"> <TextBlock Name="tbSociety" Text="{Binding Path=name}" Padding="5" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </GroupBox> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </TabItem>
  • 相关阅读:
    【算法工程师/专家(用户行为分析方向),阿里云计算有限公司】前程无忧官方招聘网站
    linux文件设备与I/O: dup和dup2函数
    【高级网页分析工程师,360安全卫士】前程无忧官方招聘网站
    分享:gzip头部格式
    C调试时常用的宏
    分享:Waterfox 18.0.1 发布,64 位的 Firefox
    开发人员应该对IIS理论层的知识了解的多一些~第三讲 网页从IIS端到客户端浏览器经历的阶段
    开发人员应该对IIS理论层的知识了解的多一些~第一讲 什么是Http?
    开发人员应该对IIS理论层的知识了解的多一些~第二讲 静态网页与动态网页如何被解释执行的
    Javascript基础与面向对象基础~目录
  • 原文地址:https://www.cnblogs.com/nanfei/p/16397952.html
Copyright © 2020-2023  润新知