ControlTemplate in WPF —— ListBox
2017-08-22 10:52
344 查看
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Shared.xaml" /> </ResourceDictionary.MergedDictionaries> <!--<SnippetListBox>--> <Style x:Key="{x:Type ListBox}" TargetType="ListBox"> <Setter Property="SnapsToDevicePixels" Value="true" /> <Setter Property="OverridesDefaultStyle" Value="true" /> <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" /> <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" /> <Setter Property="ScrollViewer.CanContentScroll" Value="true" /> <Setter Property="MinWidth" Value="120" /> <Setter Property="MinHeight" Value="95" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListBox"> <Border Name="Border" BorderThickness="1" CornerRadius="2"> <Border.Background> <SolidColorBrush Color="{StaticResource ControlLightColor}" /> </Border.Background> <Border.BorderBrush> <SolidColorBrush Color="{StaticResource BorderMediumColor}" /> </Border.BorderBrush> <ScrollViewer Margin="0" Focusable="false"> <StackPanel Margin="2" IsItemsHost="True" /> </ScrollViewer> </Border> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="false"> <Setter TargetName="Border" Property="Background"> <Setter.Value> <SolidColorBrush Color="{StaticResource DisabledControlLightColor}" /> </Setter.Value> </Setter> <Setter TargetName="Border" Property="BorderBrush"> <Setter.Value> <SolidColorBrush Color="{DynamicResource DisabledBorderLightColor}" /> </Setter.Value> </Setter> </Trigger> <Trigger Property="IsGrouping" Value="true"> <Setter Property="ScrollViewer.CanContentScroll" Value="false" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="{x:Type ListBoxItem}" TargetType="ListBoxItem"> <Setter Property="SnapsToDevicePixels" Value="true" /> <Setter Property="OverridesDefaultStyle" Value="true" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListBoxItem"> <Border x:Name="Border" Padding="2" SnapsToDevicePixels="true"> <Border.Background> <SolidColorBrush Color="Transparent" /> </Border.Background> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="SelectionStates"> <VisualState x:Name="Unselected" /> <VisualState x:Name="Selected"> <Storyboard> <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="(Panel.Background). (SolidColorBrush.Color)"> <EasingColorKeyFrame KeyTime="0" Value="{StaticResource SelectedBackgroundColor}" /> </ColorAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:Name="SelectedUnfocused"> <Storyboard> <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="(Panel.Background). (SolidColorBrush.Color)"> <EasingColorKeyFrame KeyTime="0" Value="{StaticResource SelectedUnfocusedColor}" /> </ColorAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <ContentPresenter /> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> <!--</SnippetListBox>--> </ResourceDictionary>
相关文章推荐
- ControlTemplate in WPF —— ListBox
- ControlTemplate in WPF —— ComboBox
- ControlTemplate in WPF —— DatePicker
- ControlTemplate in WPF —— ComboBox
- ControlTemplate in WPF —— ItemsControl
- ControlTemplate in WPF —— Menu
- ControlTemplate in WPF ——ScrollBar
- ControlTemplate in WPF —— DatePicker
- ControlTemplate in WPF —— Button
- ControlTemplate in WPF ——ScrollBar
- WPF Trigger for IsSelected in a DataTemplate for ListBox items
- WPF Template模版之DataTemplate与ControlTemplate的关系
- WPF为ItemsControl设置ItemsPanelTemplate
- Windowsx.h使用之ListBox control message APIs
- 获得由ControlTemplate或DataTemplate生成的控件的内部控件
- checklistbox+tabcontrol BUG or 代码太烂了?
- ControlTemplate和ItemTemplate的区别
- DevExpress之ChartControl的SeriesTemplate实例
- 第三方控件DEV的checkedListBoxControl的用法
- gridcontrol CellTemplate改变cell文本颜色