|
1 | | -<?xml version="1.0" encoding="utf-8"?> |
2 | 1 | <UserControl xmlns="https://github.com/avaloniaui" |
3 | 2 | xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
4 | 3 | xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
5 | 4 | xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
6 | 5 | xmlns:vm="clr-namespace:Modulus.App.Controls.ViewModels" |
7 | 6 | xmlns:conv="clr-namespace:Modulus.App.Converters" |
| 7 | + xmlns:controls="clr-namespace:Modulus.App.Controls" |
8 | 8 | mc:Ignorable="d" d:DesignWidth="220" d:DesignHeight="400" |
9 | 9 | x:Class="Modulus.App.Controls.NavigationBody" |
10 | 10 | x:Name="control" |
11 | | - x:DataType="vm:NavigationViewModel"> |
| 11 | + x:DataType="vm:NavigationViewModel" |
| 12 | + DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=controls:NavigationView}, Path=DataContext}"> |
12 | 13 | <Design.DataContext> |
13 | 14 | <vm:NavigationViewModel /> |
14 | 15 | </Design.DataContext> |
|
18 | 19 | </UserControl.Resources> |
19 | 20 |
|
20 | 21 | <UserControl.Styles> |
21 | | - <!-- 当控件未展开时,隐藏所有标记为label的TextBlock --> |
22 | | - <Style Selector="UserControl:not(.expanded) TextBlock.label"> |
23 | | - <Setter Property="IsVisible" Value="False" /> |
24 | | - </Style> |
25 | | - <!-- 确保展开时的样式 --> |
26 | | - <Style Selector="UserControl.expanded TextBlock.label"> |
27 | | - <Setter Property="IsVisible" Value="True" /> |
28 | | - </Style> |
29 | | - |
30 | | - <!-- 折叠状态下的按钮样式 --> |
31 | | - <Style Selector="UserControl:not(.expanded) Button"> |
| 22 | + <!-- 默认按钮样式 --> |
| 23 | + <Style Selector="Button.nav-button"> |
| 24 | + <Setter Property="Height" Value="36" /> |
| 25 | + <Setter Property="Margin" Value="0,2" /> |
32 | 26 | <Setter Property="CornerRadius" Value="8" /> |
| 27 | + <Setter Property="HorizontalAlignment" Value="Stretch" /> |
| 28 | + </Style> |
| 29 | + |
| 30 | + <!-- 折叠状态按钮样式 --> |
| 31 | + <Style Selector="Button.collapsed"> |
33 | 32 | <Setter Property="Width" Value="36" /> |
34 | | - <Setter Property="Height" Value="36" /> |
35 | | - <Setter Property="HorizontalContentAlignment" Value="Center" /> |
36 | 33 | <Setter Property="Padding" Value="8" /> |
| 34 | + <Setter Property="HorizontalAlignment" Value="Center" /> |
| 35 | + <Setter Property="HorizontalContentAlignment" Value="Center" /> |
| 36 | + </Style> |
| 37 | + |
| 38 | + <!-- 展开状态按钮样式 --> |
| 39 | + <Style Selector="Button.expanded"> |
| 40 | + <Setter Property="Padding" Value="12,8" /> |
| 41 | + <Setter Property="HorizontalContentAlignment" Value="Left" /> |
| 42 | + <Setter Property="Width" Value="196" /> |
| 43 | + </Style> |
| 44 | + |
| 45 | + <!-- 标签文本样式 --> |
| 46 | + <Style Selector="TextBlock.nav-label"> |
| 47 | + <Setter Property="IsVisible" Value="False" /> |
| 48 | + </Style> |
| 49 | + |
| 50 | + <Style Selector="TextBlock.nav-label.expanded"> |
| 51 | + <Setter Property="IsVisible" Value="True" /> |
37 | 52 | </Style> |
38 | 53 | </UserControl.Styles> |
39 | 54 |
|
40 | 55 | <Grid> |
41 | 56 | <Grid.RowDefinitions> |
42 | | - <RowDefinition Height="Auto"/> |
43 | 57 | <RowDefinition Height="Auto"/> |
44 | 58 | <RowDefinition Height="*"/> |
45 | 59 | </Grid.RowDefinitions> |
|
50 | 64 | Background="#333333" |
51 | 65 | Margin="16,0,16,12"/> |
52 | 66 |
|
53 | | - <!-- DEBUG: 显示NavigationItems数量 --> |
54 | | - <TextBlock Grid.Row="1" |
55 | | - Text="{Binding NavigationItems.Count, StringFormat='菜单项: {0}个'}" |
56 | | - Foreground="White" |
57 | | - HorizontalAlignment="Center" |
58 | | - Margin="0,0,0,8"/> |
59 | | - |
60 | 67 | <!-- 导航菜单项列表 --> |
61 | | - <ScrollViewer Grid.Row="2" |
| 68 | + <ScrollViewer Grid.Row="1" |
62 | 69 | HorizontalScrollBarVisibility="Hidden" |
63 | 70 | VerticalScrollBarVisibility="Auto"> |
64 | 71 | <ItemsControl x:Name="NavigationItemsControl" |
65 | 72 | ItemsSource="{Binding NavigationItems}" |
66 | 73 | Margin="12,0" |
67 | | - HorizontalAlignment="Center"> |
| 74 | + HorizontalAlignment="Stretch"> |
68 | 75 | <ItemsControl.ItemsPanel> |
69 | 76 | <ItemsPanelTemplate> |
70 | | - <StackPanel Spacing="8"/> |
| 77 | + <StackPanel Spacing="4"/> |
71 | 78 | </ItemsPanelTemplate> |
72 | 79 | </ItemsControl.ItemsPanel> |
73 | 80 | <ItemsControl.ItemTemplate> |
74 | 81 | <DataTemplate DataType="{x:Type vm:NavigationItemModel}"> |
75 | | - <Button Background="{Binding IsActive, Converter={StaticResource NavItemBackgroundConverter}}" |
76 | | - Foreground="White" |
77 | | - ToolTip.Tip="{Binding Label}" |
78 | | - Command="{Binding $parent[UserControl].((vm:NavigationViewModel)DataContext).NavigateToViewCommand}" |
79 | | - CommandParameter="{Binding}" |
80 | | - HorizontalAlignment="Stretch" |
81 | | - HorizontalContentAlignment="Left" |
82 | | - CornerRadius="8" |
83 | | - Margin="0,0,0,4" |
84 | | - Padding="12,8"> |
85 | | - <Grid> |
86 | | - <Grid.ColumnDefinitions> |
87 | | - <ColumnDefinition Width="Auto"/> |
88 | | - <ColumnDefinition Width="*"/> |
89 | | - </Grid.ColumnDefinitions> |
90 | | - |
91 | | - <!-- 图标 --> |
92 | | - <TextBlock Text="{Binding Icon}" |
93 | | - Grid.Column="0" |
94 | | - FontFamily="Segoe MDL2 Assets" |
95 | | - FontSize="18" |
96 | | - VerticalAlignment="Center" |
97 | | - HorizontalAlignment="Center"/> |
| 82 | + <Grid> |
| 83 | + <Button Classes="nav-button" |
| 84 | + Classes.collapsed="{Binding !$parent[UserControl].((vm:NavigationViewModel)DataContext).IsNavigationExpanded}" |
| 85 | + Classes.expanded="{Binding $parent[UserControl].((vm:NavigationViewModel)DataContext).IsNavigationExpanded}" |
| 86 | + Background="{Binding IsActive, Converter={StaticResource NavItemBackgroundConverter}}" |
| 87 | + Foreground="White" |
| 88 | + ToolTip.Tip="{Binding Label}" |
| 89 | + Command="{Binding $parent[UserControl].((vm:NavigationViewModel)DataContext).NavigateToViewCommand}" |
| 90 | + CommandParameter="{Binding}"> |
| 91 | + <Grid> |
| 92 | + <Grid.ColumnDefinitions> |
| 93 | + <ColumnDefinition Width="Auto"/> |
| 94 | + <ColumnDefinition Width="*"/> |
| 95 | + </Grid.ColumnDefinitions> |
98 | 96 |
|
99 | | - <!-- 标签文本 - 使用样式类控制可见性 --> |
100 | | - <TextBlock Text="{Binding Label}" |
101 | | - Classes="label" |
102 | | - Grid.Column="1" |
103 | | - Margin="10,0,0,0" |
104 | | - VerticalAlignment="Center"/> |
105 | | - |
106 | | - <!-- 徽章 - 调整徽章大小 --> |
107 | | - <Border IsVisible="{Binding HasBadge}" |
108 | | - Grid.Column="1" |
109 | | - Background="#FF3B30" |
110 | | - CornerRadius="6" |
111 | | - Width="12" Height="12" |
112 | | - HorizontalAlignment="Right" |
113 | | - VerticalAlignment="Top" |
114 | | - Margin="0,0,4,0"> |
115 | | - <TextBlock Text="{Binding BadgeText}" |
116 | | - FontSize="8" |
117 | | - FontWeight="Bold" |
118 | | - HorizontalAlignment="Center" |
119 | | - VerticalAlignment="Center" |
120 | | - Foreground="White"/> |
121 | | - </Border> |
122 | | - </Grid> |
123 | | - </Button> |
| 97 | + <!-- 图标 --> |
| 98 | + <TextBlock Text="{Binding Icon}" |
| 99 | + Grid.Column="0" |
| 100 | + FontFamily="Segoe MDL2 Assets" |
| 101 | + FontSize="18" |
| 102 | + VerticalAlignment="Center" |
| 103 | + HorizontalAlignment="Center"/> |
| 104 | + |
| 105 | + <!-- 标签文本 --> |
| 106 | + <TextBlock Text="{Binding Label}" |
| 107 | + Classes="nav-label" |
| 108 | + Classes.expanded="{Binding $parent[UserControl].((vm:NavigationViewModel)DataContext).IsNavigationExpanded}" |
| 109 | + Grid.Column="1" |
| 110 | + Margin="10,0,0,0" |
| 111 | + VerticalAlignment="Center"/> |
| 112 | + </Grid> |
| 113 | + </Button> |
| 114 | + |
| 115 | + <!-- 徽章 --> |
| 116 | + <Border IsVisible="{Binding HasBadge}" |
| 117 | + Background="#FF3B30" |
| 118 | + CornerRadius="6" |
| 119 | + Width="12" Height="12" |
| 120 | + HorizontalAlignment="Right" |
| 121 | + VerticalAlignment="Top" |
| 122 | + Margin="0,0,0,0"> |
| 123 | + <TextBlock Text="{Binding BadgeText}" |
| 124 | + FontSize="8" |
| 125 | + FontWeight="Bold" |
| 126 | + HorizontalAlignment="Center" |
| 127 | + VerticalAlignment="Center" |
| 128 | + Foreground="White"/> |
| 129 | + </Border> |
| 130 | + </Grid> |
124 | 131 | </DataTemplate> |
125 | 132 | </ItemsControl.ItemTemplate> |
126 | 133 | </ItemsControl> |
|
0 commit comments