schangxiang@126.com
2025-11-04 f5ed29dc26c7cd952d56ec5721a2efc43cd25992
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<UserControl x:Class="XHandler.View.User.MenuManagement"
             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:XHandler.View.User"
             xmlns:cls ="clr-namespace:XHandler.View.Classes"
             xmlns:ctrls="clr-namespace:XHandler.Controls"
             xmlns:str="clr-namespace:XHandler.Properties"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800" Loaded="UserControl_Loaded">
    <UserControl.Resources>
        <Style x:Key="treeViewItemStyle" TargetType="{x:Type TreeViewItem}">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            <Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
            <Setter Property="Padding" Value="1,0,0,0"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="IsExpanded" Value="{Binding IsExpanded}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TreeViewItem}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition MinWidth="16" Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="40"/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Border x:Name="BdBack" Margin="1" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" CornerRadius="3" Background="Transparent"></Border>
                            <ToggleButton x:Name="Expander" Grid.Row="0" Grid.Column="0" Style="{StaticResource ExpandCollapseToggleStyle}" ClickMode="Press" IsChecked="{Binding Path=IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"/>
                            <Border x:Name="Bd" Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" CornerRadius="3" SnapsToDevicePixels="True" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
                                <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" x:Name="PART_Header" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Header"/>
                            </Border>
                            <ItemsPresenter x:Name="ItemsHost" Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="2"/>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsExpanded" Value="false">
                                <Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
                            </Trigger>
                            <Trigger Property="HasItems" Value="false">
                                <Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
                            </Trigger>
                            <Trigger Property="IsSelected" Value="true">
                                <Setter Property="Background" TargetName="Bd" Value="{DynamicResource listSelectedBrush}"/>
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}}"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                            </Trigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsMouseOver" Value="true" SourceName="Bd"/>
                                    <Condition Property="IsSelected" Value="false"/>
                                </MultiTrigger.Conditions>
                                <Setter Property="Background" TargetName="Bd" Value="{DynamicResource lightBlueBrush}"/>
                            </MultiTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
 
        <HierarchicalDataTemplate x:Key="MyTreeItemTemplate" 
                                  DataType="{x:Type cls:MenuTree}" 
                                  ItemsSource="{Binding Path=Children,Mode=OneWay}">
            <StackPanel x:Name="My_SP"  Orientation="Horizontal" Margin="2" VerticalAlignment="Center">
                <CheckBox  IsChecked="{Binding Path=IsChecked}" FontSize="16" VerticalAlignment="Center"/>
                <Image Width="32" Height="32" Visibility="{Binding ImgDefault, Converter={StaticResource String2VisibilityConverter}}">
                    <Image.Source>
                        <MultiBinding Converter="{StaticResource cmdIconMultiConvert}">
                            <Binding Path="ImgDefault"/>
                            <Binding Path="IsChecked"/>
                            <Binding Path="Level"/>
                        </MultiBinding>
                    </Image.Source>
                </Image>
                <TextBlock Foreground="Black" FontSize="16" Text="{Binding Name}" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10,0,0,0" />
            </StackPanel>
        </HierarchicalDataTemplate>
 
        <Style TargetType="{x:Type CheckBox}">
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="Background" Value="White"/>
            <Setter Property="BorderBrush" Value="#FF616467"/>
            <Setter Property="FontSize" Value="16"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type CheckBox}">
                        <Grid x:Name="templateRoot" Background="Transparent" SnapsToDevicePixels="True">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Border x:Name="checkBoxBorder" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="0" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                Width="20" Height="20" BorderBrush="#FF616467" BorderThickness="1" CornerRadius="5">
                                <Grid x:Name="markGrid">
                                    <Path x:Name="optionMark" Data="M5,5 L15,18 L38,0" Stroke="White" StrokeThickness="2" Margin="4" Opacity="0" Stretch="Uniform"/>
                                    <Rectangle x:Name="indeterminateMark" Fill="#FF0E81EC"  Opacity="1" Margin="3"/>
                                </Grid>
                            </Border>
                            <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" 
                                          Grid.Column="1" ContentStringFormat="{TemplateBinding ContentStringFormat}" Focusable="False" 
                                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="5,0,0,0" 
                                          RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsChecked" Value="True">
                                <Setter Property="BorderBrush" TargetName="checkBoxBorder" Value="Transparent"/>
                                <Setter Property="Background" TargetName="checkBoxBorder" Value="#FF0E81EC"/>
                                <Setter Property="Opacity" TargetName="optionMark" Value="1"/>
                                <Setter Property="Opacity" TargetName="indeterminateMark" Value="0"/>
                            </Trigger>
                            <Trigger Property="IsChecked" Value="False">
                                <Setter Property="BorderBrush" TargetName="checkBoxBorder" Value="#FFC6CBD0"/>
                                <Setter Property="Opacity" TargetName="optionMark" Value="0"/>
                                <Setter Property="Opacity" TargetName="indeterminateMark" Value="0"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
 
 
        <Style x:Key="menuListBoxStyle" TargetType="ListBox">
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="BorderBrush" Value="{StaticResource blueBrush}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
            <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
            <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
            <Setter Property="ScrollViewer.PanningMode" Value="Both"/>
            <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListBox}">
                        <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="1" SnapsToDevicePixels="true">
                            <ScrollViewer Focusable="false" Padding="{TemplateBinding Padding}">
                                <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                            </ScrollViewer>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Background" TargetName="Bd" Value="{StaticResource ListBox.Disabled.Background}"/>
                                <Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource ListBox.Disabled.Border}"/>
                            </Trigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsGrouping" Value="true"/>
                                    <Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false"/>
                                </MultiTrigger.Conditions>
                                <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
                            </MultiTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <StackPanel/>
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="ItemContainerStyle">
                <Setter.Value>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="ListBoxItem">
                                    <Border x:Name="Border" Margin="0" Height="50" BorderThickness="0" Padding="1" Background="{TemplateBinding Background}">
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="30"/>
                                                <ColumnDefinition Width="50"/>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="auto"/>
                                                <ColumnDefinition Width="auto"/>
 
                                            </Grid.ColumnDefinitions>
                                            <CheckBox x:Name="checkbox" IsChecked="{Binding State}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                                            <Image Name="idCheckImage" Grid.Column="1" Source="{Binding Path=CheckImg}" HorizontalAlignment="Center"
                                                VerticalAlignment="Center" Width="30" Height="30" />
                                            <TextBlock Grid.Column="2" Text="{Binding Path=Name}" FontSize="16" VerticalAlignment="Center" Margin="0"/>
                                            <ctrls:ImageButton Grid.Column="3" x:Name="btnUp" NormalImage="/Assets/btn_moveup.png" Width="40" Height="40" ImageWidth="24" ImageHeight="24" VerticalAlignment="Center" HorizontalAlignment="Right"
                                      Margin="0" Visibility="Collapsed" Click="btnUp_Click"/>
                                            <ctrls:ImageButton Grid.Column="4" x:Name="btnDown" NormalImage="/Assets/btn_movedown.png" Width="40" Height="40" ImageWidth="24" ImageHeight="24" VerticalAlignment="Center" HorizontalAlignment="Right"
                                      Margin="0" Visibility="Collapsed" Click="btnDown_Click"/>
                                        </Grid>
                                    </Border>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsSelected" Value="True">
                                            <Setter Property="Background" TargetName="Border" Value="{DynamicResource listSelectedBrush}"/>
                                            <Setter Property="Visibility" TargetName="btnUp" Value="Visible"/>
                                            <Setter Property="Visibility" TargetName="btnDown" Value="Visible"/>
 
                                        </Trigger>
                                        <Trigger Property="IsMouseOver" Value="True" >
                                            <Setter TargetName="Border" Property="Background" Value="{DynamicResource lightBlueBrush}"></Setter>
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="50"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="50"/>
        </Grid.ColumnDefinitions>
        <TextBlock Grid.Row="0" Grid.Column="1" Text="{x:Static str:UserManagementResource.strMenuSet}" FontSize="16"  VerticalAlignment="Center"/>
        <Button Name="btnMenuSave" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Right" Style="{DynamicResource BlueButtonStyle}" Content="{x:Static str:UserManagementResource.strSave}"
                Foreground="White" Background="{DynamicResource blueBrush}" Click="btnMenuSave_Click" Width="80" Height="35" Margin="0 0 300 0" FontSize="16"/>
        <ListBox x:Name="listboxMenu" Grid.Row="1" Grid.Column="1" Style="{DynamicResource menuListBoxStyle}"
                 Margin="0 0 300 0" HorizontalAlignment="Stretch"/>
        <TextBlock Grid.Row="0" Grid.Column="2" Text="{x:Static str:UserManagementResource.strCommandSet}" FontSize="16"  VerticalAlignment="Center"/>
        <TreeView Grid.Row="1" Grid.Column="2" x:Name="tv" ItemContainerStyle="{StaticResource treeViewItemStyle}" Margin="0 0 300 0"
                          ItemTemplate="{StaticResource MyTreeItemTemplate}" BorderThickness="1" BorderBrush="{StaticResource blueBrush}">
        </TreeView>
 
        <Button Name="btnCommandSave" Grid.Row="0" Grid.Column="2" HorizontalAlignment="Right" Style="{DynamicResource BlueButtonStyle}" Content="{x:Static str:UserManagementResource.strSave}"
                Foreground="White" Background="{DynamicResource blueBrush}" Click="btnCommandSave_Click" Width="80" Height="35" Margin="0 0 300 0" FontSize="16"/>
    </Grid>
</UserControl>