Instantly share code, notes, and snippets.
Last active
December 29, 2015 00:59
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save Perikles/7590155 to your computer and use it in GitHub Desktop.
WebPopupMenu WPF Styles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ResourceDictionary | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:core="clr-namespace:Awesomium.Core;assembly=Awesomium.Core" | |
xmlns:awe="clr-namespace:Awesomium.Windows.Controls" | |
xmlns:cm="clr-namespace:System.ComponentModel;assembly=PresentationFramework" | |
xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase" | |
xmlns:om ="clr-namespace:System.Collections.ObjectModel;assembly=System" | |
xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" | |
xmlns:sys="clr-namespace:System;assembly=mscorlib"> | |
<!-- WebMenuListItem --> | |
<Style x:Key="WebMenuListItem" TargetType="{x:Type ListBoxItem}"> | |
<Setter Property="FocusVisualStyle" Value="{x:Null}" /> | |
<Setter Property="Background" Value="Transparent"/> | |
<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="IsSelected" Value="{Binding IsInitialSelection, Mode=OneWay}" /> | |
<Setter Property="IsEnabled" Value="{Binding IsEnabled, Mode=OneWay}" /> | |
<Setter Property="MinHeight" Value="{Binding DataContext.MenuInfo.ItemHeight, RelativeSource={RelativeSource AncestorType={x:Type ListBox}}}" /> | |
<Setter Property="BorderThickness" Value="0,1" /> | |
<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> | |
<MultiDataTrigger> | |
<MultiDataTrigger.Conditions> | |
<Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="True" /> | |
<Condition Binding="{Binding Type}" Value="Option" /> | |
</MultiDataTrigger.Conditions> | |
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/> | |
<Setter Property="BorderBrush" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/> | |
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/> | |
<Setter Property="FocusManager.FocusedElement" Value="{Binding RelativeSource={RelativeSource Self}}" /> | |
</MultiDataTrigger> | |
<MultiDataTrigger> | |
<MultiDataTrigger.Conditions> | |
<Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="False" /> | |
<Condition Binding="{Binding IsInitialSelection}" Value="True" /> | |
<Condition Binding="{Binding Type}" Value="Option" /> | |
</MultiDataTrigger.Conditions> | |
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> | |
<Setter Property="BorderBrush" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/> | |
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> | |
</MultiDataTrigger> | |
<MultiDataTrigger> | |
<MultiDataTrigger.Conditions> | |
<Condition Binding="{Binding IsFocused, RelativeSource={RelativeSource Self}}" Value="True" /> | |
<Condition Binding="{Binding Type}" Value="Option" /> | |
</MultiDataTrigger.Conditions> | |
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/> | |
<Setter Property="BorderBrush" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/> | |
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/> | |
<Setter Property="FocusManager.FocusedElement" Value="{Binding RelativeSource={RelativeSource Self}}" /> | |
</MultiDataTrigger> | |
<Trigger Property="IsEnabled" Value="false"> | |
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> | |
</Trigger> | |
</ControlTemplate.Triggers> | |
</ControlTemplate> | |
</Setter.Value> | |
</Setter> | |
</Style> | |
<!-- WebPopupMenu --> | |
<Style TargetType="{x:Type awe:WebPopupMenu}" BasedOn="{StaticResource {x:Type ListBox}}"> | |
<Setter Property="DataContext" Value="{Binding RelativeSource={RelativeSource Self}}" /> | |
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" /> | |
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" /> | |
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" /> | |
<Setter Property="BorderThickness" Value="1" /> | |
<Setter Property="MaxHeight" Value="{Binding MaxDropDownHeight}" /> | |
<Setter Property="ItemsSource" Value="{Binding MenuItems}" /> | |
<Setter Property="Padding" Value="-1" /> | |
<Setter Property="VerticalAlignment" Value="Stretch" /> | |
<Setter Property="HorizontalContentAlignment" Value="Stretch" /> | |
<Setter Property="VerticalContentAlignment" Value="Center" /> | |
<Setter Property="VirtualizingStackPanel.IsVirtualizing" Value="False" /> | |
<Setter Property="VirtualizingStackPanel.VirtualizationMode" Value="Recycling" /> | |
<Setter Property="SelectionMode" Value="Extended" /> | |
<Setter Property="ItemContainerStyle" Value="{StaticResource WebMenuListItem}" /> | |
<Setter Property="Opacity" Value="{Binding PlacementTarget.Opacity}" /> | |
<Setter Property="StaysOpen" Value="False" /> | |
<Setter Property="FocusManager.IsFocusScope" Value="True" /> | |
<Setter Property="DefaultGroupStyle"> | |
<Setter.Value> | |
<GroupStyle> | |
<GroupStyle.ContainerStyle> | |
<Style TargetType="{x:Type GroupItem}"> | |
<Setter Property="FontSize" Value="{Binding DataContext.MenuInfo.ItemFontSize, RelativeSource={RelativeSource AncestorType={x:Type ListBox}}}" /> | |
<Setter Property="TextOptions.TextFormattingMode" Value="Display" /> | |
<Setter Property="RenderOptions.ClearTypeHint" Value="Enabled" /> | |
<Setter Property="Template"> | |
<Setter.Value> | |
<ControlTemplate TargetType="{x:Type GroupItem}"> | |
<StackPanel x:Name="groupPanel"> | |
<TextBlock | |
x:Name="groupLabel" | |
Text="{Binding Name}" | |
VerticalAlignment="Center" | |
Margin="5" | |
MinHeight="{Binding DataContext.MenuInfo.ItemHeight, RelativeSource={RelativeSource AncestorType={x:Type ListBox}}}" | |
FontWeight="Bold"/> | |
<ItemsPresenter /> | |
</StackPanel> | |
<ControlTemplate.Triggers> | |
<DataTrigger Binding="{Binding Name}" Value="{x:Null}"> | |
<Setter TargetName="groupLabel" Property="Visibility" Value="Collapsed" /> | |
<Setter TargetName="groupPanel" Property="Margin" Value="0" /> | |
</DataTrigger> | |
</ControlTemplate.Triggers> | |
</ControlTemplate> | |
</Setter.Value> | |
</Setter> | |
</Style> | |
</GroupStyle.ContainerStyle> | |
</GroupStyle> | |
</Setter.Value> | |
</Setter> | |
<Setter Property="ItemTemplate"> | |
<Setter.Value> | |
<DataTemplate DataType="{x:Type core:WebMenuItem}"> | |
<TextBlock | |
x:Name="label" | |
Text="{Binding Label}" | |
ToolTip="{Binding ToolTip}" | |
Margin="0,0,0,2" | |
VerticalAlignment="Center"/> | |
<DataTemplate.Triggers> | |
<DataTrigger Binding="{Binding Type}" Value="Group"> | |
<Setter TargetName="label" Property="FontWeight" Value="Bold" /> | |
</DataTrigger> | |
</DataTemplate.Triggers> | |
</DataTemplate> | |
</Setter.Value> | |
</Setter> | |
</Style> | |
</ResourceDictionary> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment