alielie
2025-03-03 21e28b068c8d0763a6d4ab613388a77a0db157fb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<UserControl x:Class="WPFProject.Controls.MainTabControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WPFProject.Controls"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/HMI.UI;component/Style/Colors.xaml"/>
            </ResourceDictionary.MergedDictionaries>
 
            <Style TargetType="ListBox" x:Key="ListBoxItemStyle1">
                <Setter Property="Background" Value="{StaticResource PrimaryColor}"/>
                <Setter Property="ItemContainerStyle">
                    <Setter.Value>
                        <Style TargetType="ListBoxItem">
                            <Setter Property="Margin" Value="0"/>
                            <Setter Property="Padding" Value="0"/>
                            <Setter Property="Foreground" Value="{StaticResource PrimaryColorContract}"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="ListBoxItem">
                                        <Border x:Name="border" Background="{StaticResource PrimaryColor}" 
                                                Padding="10" Margin="0" BorderThickness="0,0,1,1" 
                                                BorderBrush="Gray">
                                            <!-- 内容呈现器 -->
                                            <StackPanel>
                                                <ContentPresenter x:Name="cp" Content="{TemplateBinding Content}" 
                                                                   ContentStringFormat="{TemplateBinding ContentStringFormat}" 
                                                                   ContentTemplate="{TemplateBinding ContentTemplate}"  />
                                            </StackPanel>
                                        </Border>
 
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsSelected" Value="True">
                                                <Setter TargetName="border" Property="Background" 
                                                        Value="{StaticResource WorkspaceBackground}"/>
                                                <Setter Property="Foreground" Value="{StaticResource PrimaryColor}"/>
                                                <Setter TargetName="border" Property="BorderThickness" Value="0,0,0,0"/>
                                            </Trigger>
 
                                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=Self}, Path=(ItemsControl.AlternationIndex)}" Value="0">
                                                <Setter TargetName="border" Property="BorderThickness" Value="1,0,1,0" />
                                            </DataTrigger>
 
                                            <Trigger Property="IsMouseOver" Value="True">
                                                <Setter TargetName="border" Property="Background" Value="{StaticResource SecondPrimaryColor}" />
                                                <Setter Property="Foreground" Value="{StaticResource SecondPrimaryColorContract}" />
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </Setter.Value>
                </Setter>
                <Setter Property="ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <StackPanel HorizontalAlignment="Left" Orientation="Horizontal"/>
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
                <Setter Property="ItemTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" VerticalAlignment="Center" >
                                <Image Width="20" Height="20" Margin="5" Source="{Binding Icon}"/>
                                <Label x:Name="txt" BorderThickness="0" 
                                       Foreground="{Binding Foreground,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ListBoxItem}}"
                                       FontWeight="Bold" 
                                       FontSize="16"
                                       VerticalContentAlignment="Center" 
                                       HorizontalAlignment="Left"
                                       Content="{Binding Name}" ToolTip="{Binding Name}"/>
                            </StackPanel>
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>
 
    <Grid x:Name="mainGrid">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
 
        <ListBox Grid.Row="0" x:Name="Menu" Margin="0" Padding="-1"
                 Style="{StaticResource ListBoxItemStyle1}"
                 BorderBrush="Gray"
                 BorderThickness="0,1,0,1"
                 Visibility="{Binding MenuVisibility}"
                 SelectionChanged="Menu_SelectionChanged"
                 SelectedItem="{Binding SelectedMenu}"
                 AlternationCount="{Binding MenuItemsCount}" ItemsSource="{Binding MenuItems}">
 
        </ListBox>
 
        <ListBox Grid.Row="1" x:Name="SubMenu" Margin="0" Padding="-1"
         Style="{StaticResource ListBoxItemStyle1}"
         BorderBrush="Gray"
                 Visibility="{Binding MenuVisibility}"
                 SelectedItem="{Binding SelectedSubMenu}" AlternationCount="{Binding SubMenuItemsCount}"
                 SelectionChanged="SubMenu_SelectionChanged"
BorderThickness="0" ItemsSource="{Binding SubMenuItems}">
        </ListBox>
 
        <Border x:Name="page"  Grid.Row="2" BorderThickness="0" Margin="0" Padding="0">
            
        </Border>
    </Grid>
</UserControl>