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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<UserControl x:Class="XHandler.View.User.EditAuthority"
             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:str="clr-namespace:XHandler.Properties"
             xmlns:cls ="clr-namespace:XHandler.Class"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800" Loaded="UserControl_Loaded">
    <UserControl.Resources>
        <Style TargetType="{x:Type RadioButton}">
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="Background" Value="White"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type RadioButton}">
                        <Grid x:Name="templateRoot" Background="Transparent" SnapsToDevicePixels="True">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Ellipse x:Name="outerElipse" Width="20" Height="20" StrokeThickness="1" Stroke="#FF616467" Fill="White" Margin="0"
                                 HorizontalAlignment="Center" VerticalAlignment="Center"/>
                            <Ellipse x:Name="innerElipse" Width="6" Height="6" StrokeThickness="0" Fill="White" Margin="0" Opacity="0"
                                 HorizontalAlignment="Center" VerticalAlignment="Center"/>
                            <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="IsMouseOver" Value="True">
                                <Setter Property="Opacity" TargetName="outerElipse" Value="0.8"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Fill" TargetName="outerElipse" Value="#FFE6E6E6"/>
                            </Trigger>
                            <!--<Trigger Property="IsPressed" Value="True">
                            <Setter Property="Background" TargetName="outerElipse" Value="#20FFFFFF"/>
                        </Trigger>-->
                            <Trigger Property="IsChecked" Value="True">
                                <Setter Property="Fill" TargetName="outerElipse" Value="{DynamicResource blueBrush}"/>
                                <Setter Property="Opacity" TargetName="innerElipse" Value="1"/>
                                <Setter Property="StrokeThickness" TargetName="outerElipse" Value="0"/>
                            </Trigger>
                            <Trigger Property="IsChecked" Value="{x:Null}">
                                <Setter Property="Opacity" TargetName="innerElipse" Value="0"/>
                                <Setter Property="StrokeThickness" TargetName="outerElipse" Value="1"/>
                                <Setter Property="Fill" TargetName="outerElipse" Value="white"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
 
        <PathGeometry x:Key="TreeArrow" Figures="M0,0 L0,6 L6,0 z"/>
        <Style x:Key="ExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}">
            <Setter Property="Focusable" Value="False"/>
            <Setter Property="Width" Value="16"/>
            <Setter Property="Height" Value="16"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                        <Border Background="Transparent" Height="16" Padding="5,5,5,5" Width="16">
                            <Path x:Name="ExpandPath" Data="{StaticResource TreeArrow}" Fill="Transparent" Stroke="#FF989898">
                                <Path.RenderTransform>
                                    <RotateTransform Angle="135" CenterY="3" CenterX="3"/>
                                </Path.RenderTransform>
                            </Path>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Stroke" TargetName="ExpandPath" Value="#FF1BBBFA"/>
                                <Setter Property="Fill" TargetName="ExpandPath" Value="Transparent"/>
                            </Trigger>
                            <Trigger Property="IsChecked" Value="True">
                                <Setter Property="RenderTransform" TargetName="ExpandPath">
                                    <Setter.Value>
                                        <RotateTransform Angle="180" CenterY="3" CenterX="3"/>
                                    </Setter.Value>
                                </Setter>
                                <Setter Property="Fill" TargetName="ExpandPath" Value="#FF595959"/>
                                <Setter Property="Stroke" TargetName="ExpandPath" Value="#FF262626"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
 
        <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="30"/>
                                <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>
                            <!--<MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsSelected" Value="true"/>
                                    <Condition Property="IsSelectionActive" Value="false"/>
                                </MultiTrigger.Conditions>
                                <Setter Property="Background" TargetName="Bd" Value="{DynamicResource lightBlueBrush}"/>
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}}"/>
                            </MultiTrigger>-->
                            <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}"/>
                                <!--<Setter Property="BorderBrush" TargetName="BdBack" Value="{DynamicResource lightBlueBrush}" />-->
                            </MultiTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <!--<EventSetter Event="PreviewMouseRightButtonDown"  Handler="TreeViewItem_PreviewMouseRightButtonDown"/>-->
        </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"/>
                <!--<ContentPresenter  Content="{Binding Path=Name,Mode=OneTime}" Margin="2,0"/>-->
                <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">
                                    <!--<Rectangle x:Name="line1" Fill="#FF19939D"  Opacity="0" Height="2" Width="{TemplateBinding Width}" VerticalAlignment="Top"/>
                                <Rectangle x:Name="line2" Fill="#FF19939D"  Opacity="0" Height="{TemplateBinding Height}" Width="2" HorizontalAlignment="Left"/>-->
                                    <!--<Path x:Name="optionMark" Data="F1M17,5L9,16 2,10 5,8 8,11 15,2 z" Fill="White" Margin="4" Opacity="0" Stretch="Uniform"/>-->
                                    <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>
    </UserControl.Resources>
 
    <Grid x:Name="root" Background="#01FFFFFF" PreviewMouseDown="root_PreviewMouseDown">
        <Border x:Name="border" Width="0" Visibility="Collapsed" HorizontalAlignment="Right" Background="White" BorderBrush="LightGray"
                BorderThickness="1">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="100"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="50"/>
                    <RowDefinition Height="20"/>
                    <RowDefinition Height="40"/>
                    <RowDefinition Height="40"/>
                    <RowDefinition Height="100"/>
                    <RowDefinition Height="40"/>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="60"/>
                </Grid.RowDefinitions>
 
                <Grid Grid.Row="0" Grid.ColumnSpan="2">
                    <TextBlock x:Name="title" Text="角色编辑" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="20 0" FontSize="20"
                               Foreground="Black" FontWeight="Bold"/>
                    <Button Content="×" HorizontalAlignment="Right" VerticalAlignment="Center" VerticalContentAlignment="Center" Margin="10 0" FontSize="28" Width="40" Height="40"
                            FontWeight="Bold" Foreground="Black" Style="{DynamicResource BlueButtonStyle}" Background="White" Click="Button_Click" BorderThickness="0"/>
                    <Rectangle Height="1" Fill="Gray" VerticalAlignment="Bottom" Margin="15 0"/>
                </Grid>
 
                <TextBlock Grid.Row="2" Grid.Column="0" Text="角色名" FontSize="16" VerticalAlignment="Center" HorizontalAlignment="Right"/>
                <TextBlock x:Name="textboxRoleName" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Stretch" Text="{Binding Name}"
                     VerticalAlignment="Center" FontSize="16" Margin="20 0 100 0" FontWeight="Bold"/>
 
 
                <TextBlock Grid.Row="3" Grid.Column="0" Text="角色状态" FontSize="16" VerticalAlignment="Center" HorizontalAlignment="Right"/>
                <ComboBox x:Name="comboxStatus" Grid.Row="3" Grid.Column="1" Height="35" VerticalContentAlignment="Center" FontSize="16"
                      Background="White" IsEditable="False" Margin="20 0 100 0" SelectionChanged="comboxStatus_SelectionChanged"/>
 
                <TextBlock Grid.Row="4" Grid.Column="0" Text="角色描述" FontSize="16" VerticalAlignment="Top" HorizontalAlignment="Right"
                           Margin="0 15"/>
                <TextBox x:Name="textboxRemark" Grid.Row="4" Grid.Column="1" Height="80" VerticalContentAlignment="Top" HorizontalAlignment="Stretch" 
                     VerticalAlignment="Center" FontSize="16" Margin="20 0 100 0" Text="{Binding Remarks}"/>
 
                <TextBlock Grid.Row="5" Grid.Column="0" Text="数据权限" FontSize="16" VerticalAlignment="Center" HorizontalAlignment="Right"
                           />
                <StackPanel Orientation="Horizontal" Grid.Row="5" Grid.Column="1" Margin="20 0 100 0">
                    <RadioButton x:Name="radioBtnSelf" Content="只查看本人数据" FontSize="16" 
                                 VerticalAlignment="Center" HorizontalAlignment="Right" Margin="5 0 15 0" Checked="radioBtnSelf_Checked"/>
                    <RadioButton x:Name="radioBtnAll" Content="查看全部数据" FontSize="16" 
                                 VerticalAlignment="Center" HorizontalAlignment="Right" Margin="5 0 15 0" Checked="radioBtnAll_Checked"/>
                </StackPanel>
 
                <TextBlock Grid.Row="6" Grid.Column="0" Text="操作权限" FontSize="16" VerticalAlignment="Top" HorizontalAlignment="Right"
                           Margin="0 15"/>
                <TreeView Grid.Row="6" Grid.Column="1" x:Name="tv" ItemContainerStyle="{StaticResource treeViewItemStyle}" Margin="20 10 100 0"
                          ItemTemplate="{StaticResource MyTreeItemTemplate}" BorderThickness="0">
                </TreeView>
 
 
                <Button Content="取消" x:Name="btnCancel" Grid.Row="7" Grid.Column="1" HorizontalAlignment="Right" 
                        Foreground="Black" Style="{DynamicResource BlueButtonStyle}" Background="White" BorderThickness="1" BorderBrush="Black"
                        Height="40" Width="100" Click="btnCancel_Click" FontSize="16" Margin="0 0 150 0" Visibility="Collapsed"/>
 
                <Button Content="保存" x:Name="btnSave" Grid.Row="7" Grid.Column="1" HorizontalAlignment="Right" 
                        Foreground="White" Style="{DynamicResource BlueButtonStyle}" Background="{DynamicResource blueBrush}" BorderThickness="0"
                        Height="40" Width="100" Click="btnSave_Click" FontSize="16" Margin="0 0 20 0"/>
 
            </Grid>
        </Border>
    </Grid>
</UserControl>