Skip to content

Commit 1ab5736

Browse files
committed
fix: nav menu items has vertical orientation
1 parent 9ff0084 commit 1ab5736

1 file changed

Lines changed: 34 additions & 6 deletions

File tree

Desktop/MainWindow.xaml

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,39 @@
2020
</backendAvailabilityConverters:BoolToImageConverter>
2121

2222
<backendAvailabilityConverters:BoolToAvailabilityTextConverter x:Key="BoolToAvailabilityTextConverter" />
23+
24+
<!-- This style is required since the Fluent theme currently applied ControlTemplate arranges top-level items
25+
with its own horizontal panel. Setting ItemsPanel directly on Menu, as done previously, doesn't touch that
26+
panel, so MenuItems stay horizontal. -->
27+
<Style x:Key="VerticalMenu" TargetType="{x:Type Menu}" BasedOn="{StaticResource {x:Type Menu}}">
28+
<Setter Property="Template">
29+
<Setter.Value>
30+
<ControlTemplate TargetType="{x:Type Menu}">
31+
<Border
32+
Background="{TemplateBinding Background}"
33+
BorderBrush="{TemplateBinding BorderBrush}"
34+
BorderThickness="{TemplateBinding BorderThickness}"
35+
Padding="{TemplateBinding Padding}">
36+
<!-- ItemsPresenter ensures ItemsPanelTemplate below is honored -->
37+
<ScrollViewer HorizontalScrollBarVisibility="Disabled"
38+
VerticalScrollBarVisibility="Auto"
39+
CanContentScroll="True">
40+
<ItemsPresenter />
41+
</ScrollViewer>
42+
</Border>
43+
</ControlTemplate>
44+
</Setter.Value>
45+
</Setter>
46+
47+
<!-- Now this actually controls the top-level layout -->
48+
<Setter Property="ItemsPanel">
49+
<Setter.Value>
50+
<ItemsPanelTemplate>
51+
<VirtualizingStackPanel Orientation="Vertical" />
52+
</ItemsPanelTemplate>
53+
</Setter.Value>
54+
</Setter>
55+
</Style>
2356
</Window.Resources>
2457
<DockPanel>
2558
<StatusBar DockPanel.Dock="Bottom">
@@ -42,12 +75,7 @@
4275
</Grid.ColumnDefinitions>
4376
<StackPanel Grid.Column="0" Margin="{StaticResource DefaultMargin}">
4477
<Label HorizontalAlignment="Center">Views</Label>
45-
<Menu>
46-
<Menu.ItemsPanel>
47-
<ItemsPanelTemplate>
48-
<VirtualizingStackPanel Orientation="Vertical" />
49-
</ItemsPanelTemplate>
50-
</Menu.ItemsPanel>
78+
<Menu Style="{StaticResource VerticalMenu}">
5179
<MenuItem Header="_1 - Tasks List" Click="NavigateToTaskList" />
5280
<MenuItem Header="_2 - Project Tree" Click="NavigateToProjectTree" />
5381
</Menu>

0 commit comments

Comments
 (0)