Skip to content

Commit 783ff98

Browse files
committed
Theme ContextMenu
1 parent 197be57 commit 783ff98

File tree

4 files changed

+127
-0
lines changed

4 files changed

+127
-0
lines changed

src/StructuredLogViewer/StructuredLogViewer.csproj

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
<RuntimeHostConfigurationOption Include="Switch.System.Windows.Media.EnableHardwareAccelerationInRdp" Value="true" />
2525
</ItemGroup>
2626

27+
<ItemGroup>
28+
<!-- needed for SystemDropShadowChrome used in ComboBox.xaml -->
29+
<Reference Include="PresentationFramework.Aero2" Condition="$(TargetFramework) == 'net472'" />
30+
</ItemGroup>
31+
2732
<ItemGroup>
2833
<PackageReference Include="AdonisUI" />
2934
<PackageReference Include="AdonisUI.ClassicTheme" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:theme="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero2">
4+
5+
<Style x:Key="{x:Type ContextMenu}"
6+
TargetType="{x:Type ContextMenu}">
7+
<Setter Property="Background"
8+
Value="{DynamicResource ContextMenu.Static.Background}"/>
9+
<Setter Property="FontFamily"
10+
Value="{DynamicResource {x:Static SystemFonts.MenuFontFamilyKey}}"/>
11+
<Setter Property="FontSize"
12+
Value="{DynamicResource {x:Static SystemFonts.MenuFontSizeKey}}"/>
13+
<Setter Property="FontStyle"
14+
Value="{DynamicResource {x:Static SystemFonts.MenuFontStyleKey}}"/>
15+
<Setter Property="FontWeight"
16+
Value="{DynamicResource {x:Static SystemFonts.MenuFontWeightKey}}"/>
17+
<Setter Property="Foreground"
18+
Value="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}"/>
19+
<Setter Property="VerticalContentAlignment"
20+
Value="Center"/>
21+
<Setter Property="BorderThickness"
22+
Value="1"/>
23+
<Setter Property="BorderBrush"
24+
Value="{DynamicResource ContextMenu.Static.BorderBrush}"/>
25+
<Setter Property="Padding"
26+
Value="2"/>
27+
<Setter Property="Grid.IsSharedSizeScope"
28+
Value="true"/>
29+
<Setter Property="HasDropShadow"
30+
Value="{DynamicResource {x:Static SystemParameters.DropShadowKey}}"/>
31+
<Setter Property="ScrollViewer.PanningMode"
32+
Value="Both"/>
33+
<Setter Property="Stylus.IsFlicksEnabled"
34+
Value="False"/>
35+
<Setter Property="Template">
36+
<Setter.Value>
37+
<ControlTemplate TargetType="{x:Type ContextMenu}">
38+
<theme:SystemDropShadowChrome Name="Shdw"
39+
Color="Transparent"
40+
SnapsToDevicePixels="true">
41+
<Border Name="ContextMenuBorder" Background="{TemplateBinding Background}"
42+
BorderBrush="{TemplateBinding BorderBrush}"
43+
BorderThickness="{TemplateBinding BorderThickness}">
44+
<ScrollViewer Name="ContextMenuScrollViewer"
45+
Grid.ColumnSpan="2" Margin="1,0"
46+
Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type FrameworkElement}, ResourceId=MenuScrollViewer}}">
47+
<Grid RenderOptions.ClearTypeHint="Enabled">
48+
<Canvas Height="0" Width="0" HorizontalAlignment="Left" VerticalAlignment="Top">
49+
<Rectangle
50+
Name="OpaqueRect"
51+
Height="{Binding ElementName=ContextMenuBorder,Path=ActualHeight}"
52+
Width="{Binding ElementName=ContextMenuBorder,Path=ActualWidth}"
53+
Fill="{Binding ElementName=ContextMenuBorder,Path=Background}" />
54+
</Canvas>
55+
<Rectangle Fill="{DynamicResource ContextMenu.Header.Background}"
56+
HorizontalAlignment="Left"
57+
Width="28"
58+
Margin="1,2"
59+
RadiusX="2"
60+
RadiusY="2"/>
61+
<Rectangle HorizontalAlignment="Left"
62+
Width="1"
63+
Margin="29,2,0,2"
64+
Fill="{DynamicResource ContextMenu.Header.LeftBorderBrush}"/>
65+
<Rectangle HorizontalAlignment="Left"
66+
Width="1"
67+
Margin="30,2,0,2"
68+
Fill="{DynamicResource ContextMenu.Header.RightBorderBrush}"/>
69+
<ItemsPresenter Name="ItemsPresenter" Margin="{TemplateBinding Padding}"
70+
KeyboardNavigation.DirectionalNavigation="Cycle"
71+
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
72+
</Grid>
73+
</ScrollViewer>
74+
</Border>
75+
</theme:SystemDropShadowChrome>
76+
<ControlTemplate.Triggers>
77+
<Trigger Property="HasDropShadow"
78+
Value="true">
79+
<Setter TargetName="Shdw"
80+
Property="Margin"
81+
Value="0,0,5,5"/>
82+
<Setter TargetName="Shdw"
83+
Property="Color"
84+
Value="#71000000"/>
85+
</Trigger>
86+
<Trigger SourceName="ContextMenuScrollViewer"
87+
Property="ScrollViewer.CanContentScroll"
88+
Value="false" >
89+
<Setter TargetName="OpaqueRect"
90+
Property="Canvas.Top"
91+
Value="{Binding ElementName=ContextMenuScrollViewer, Path=VerticalOffset}" />
92+
<Setter TargetName="OpaqueRect"
93+
Property="Canvas.Left"
94+
Value="{Binding ElementName=ContextMenuScrollViewer, Path=HorizontalOffset}" />
95+
</Trigger>
96+
</ControlTemplate.Triggers>
97+
</ControlTemplate>
98+
</Setter.Value>
99+
</Setter>
100+
</Style>
101+
102+
</ResourceDictionary>

src/StructuredLogViewer/themes/Generic.xaml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<ResourceDictionary.MergedDictionaries>
1010
<ResourceDictionary Source="/StructuredLogViewer;component/themes/Button.xaml" />
1111
<ResourceDictionary Source="/StructuredLogViewer;component/themes/CheckBox.xaml" />
12+
<ResourceDictionary Source="/StructuredLogViewer;component/themes/ContextMenu.xaml" />
1213
<ResourceDictionary Source="/StructuredLogViewer;component/themes/GroupBox.xaml" />
1314
<ResourceDictionary Source="/StructuredLogViewer;component/themes/MenuItem.xaml" />
1415
<ResourceDictionary Source="/StructuredLogViewer;component/themes/ScrollBar.xaml" />

src/StructuredLogViewer/themes/ThemeManager.cs

+19
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ public static void UpdateTheme()
9191
var buttonDisabledBorder = "#FFADB2B5";
9292
var buttonDisabledForeground = "#FF838383";
9393

94+
var contextMenuStaticBackground = "#F5F5F5";
95+
var contextMenuStaticBorderBrush = "#FF959595";
96+
var contextMenuHeaderBackground = "#F1F1F1";
97+
var contextMenuHeaderLeftBorderBrush = "#E2E3E3";
98+
var contextMenuHeaderRightBorderBrush = "White";
99+
94100
var optionMarkStaticBackground = "#FFFFFFFF";
95101
var optionMarkStaticBorder = "#FF707070";
96102
var optionMarkStaticGlyph = "#FF212121";
@@ -172,6 +178,7 @@ public static void UpdateTheme()
172178
var color900 = "#212121";
173179
var foregroundColor = "#e5ffffff";
174180
var foregroundDisabledColor = "#50ffffff";
181+
var foregroundSecondaryColor = "#b3ffffff";
175182
var selectionColor1 = "#3b5464";
176183
var selectionColor1Opacity05 = "#803b5464";
177184
var selectionColor2 = "#36A2DB";
@@ -219,6 +226,12 @@ public static void UpdateTheme()
219226
buttonDisabledBorder = color800;
220227
buttonDisabledForeground = foregroundDisabledColor;
221228

229+
contextMenuStaticBackground = color800;
230+
contextMenuStaticBorderBrush = color700;
231+
contextMenuHeaderBackground = color800;
232+
contextMenuHeaderLeftBorderBrush = foregroundSecondaryColor;
233+
contextMenuHeaderRightBorderBrush = "Transparent";
234+
222235
optionMarkStaticBackground = color800;
223236
optionMarkStaticBorder = color700;
224237
optionMarkStaticGlyph = foregroundColor;
@@ -306,6 +319,12 @@ public static void UpdateTheme()
306319
SetResource("Button.Disabled.Border", GetBrush(buttonDisabledBorder));
307320
SetResource("Button.Disabled.Foreground", GetBrush(buttonDisabledForeground));
308321

322+
SetResource("ContextMenu.Static.Background", GetBrush(contextMenuStaticBackground));
323+
SetResource("ContextMenu.Static.BorderBrush", GetBrush(contextMenuStaticBorderBrush));
324+
SetResource("ContextMenu.Header.Background", GetBrush(contextMenuHeaderBackground));
325+
SetResource("ContextMenu.Header.LeftBorderBrush", GetBrush(contextMenuHeaderLeftBorderBrush));
326+
SetResource("ContextMenu.Header.RightBorderBrush", GetBrush(contextMenuHeaderRightBorderBrush));
327+
309328
SetResource("OptionMark.Static.Background", GetBrush(optionMarkStaticBackground));
310329
SetResource("OptionMark.Static.Border", GetBrush(optionMarkStaticBorder));
311330
SetResource("OptionMark.Static.Glyph", GetBrush(optionMarkStaticGlyph));

0 commit comments

Comments
 (0)