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
<UserControl x:Class="HxUserManagement.Views.AuthorityCenter"
             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:HxUserManagement.Views"
             xmlns:str="clr-namespace:HxUserManagement.Properties"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <Style x:Key="dataGridColumnHeaderStyle" TargetType="DataGridColumnHeader">
            <Setter Property="SnapsToDevicePixels" Value="True" />
            <Setter Property="MinWidth" Value="0" />
            <Setter Property="MinHeight" Value="28" />
            <Setter Property="Foreground" Value="#323433" />
            <Setter Property="FontSize" Value="16" />
            <Setter Property="Cursor" Value="Hand" />
            <Setter Property="Height" Value="40"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="DataGridColumnHeader">
                        <Border x:Name="BackgroundBorder" BorderThickness="0,0,0,0" BorderBrush="LightGray" Width="Auto" Background="{DynamicResource lightGrayBrush}">
                            <Grid >
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <ContentPresenter  Margin="0,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Left"/>
                                <!--<Path x:Name="SortArrow" Visibility="Collapsed" Data="M0,0 L1,0 0.5,1 z" Stretch="Fill"  Grid.Column="2" Width="8" Height="6" Fill="White" Margin="0,0,50,0" 
                            VerticalAlignment="Center" RenderTransformOrigin="1,1" />-->
                                <!--<Rectangle Width="1" Fill="LightGray" HorizontalAlignment="Right" Grid.ColumnSpan="1" />-->
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
 
        <Style x:Key="rowStyle" TargetType="DataGridRow">
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="BorderBrush" Value="Transparent"/>
            <Setter Property="Background" Value="White" />
            <Setter Property="Height" Value="40"/>
            <Setter Property="FontSize" Value="16" />
            <Setter Property="Foreground" Value="Black" />
            <Style.Triggers>
                <!--<Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="{DynamicResource lightBlueBrush}"/>
                    <Setter Property="Foreground" Value="Black"/>
                </Trigger>-->
 
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="Background" Value="{DynamicResource lightBlueBrush}"/>
                    <!--<Setter Property="Foreground" Value="Red"/>-->
                </Trigger>
            </Style.Triggers>
        </Style>
 
        <!--单元格样式触发-->
        <Style x:Key="cellStyle" TargetType="DataGridCell">
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="BorderBrush" Value="Transparent"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="DataGridCell">
                        <TextBlock TextAlignment="Left" VerticalAlignment="Center" Foreground="Black" >
                           <ContentPresenter />
                        </TextBlock>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <!--<EventSetter Event="PreviewMouseDoubleClick" Handler="DataGridCell_PreviewMouseDoubleClick"/>-->
            <Style.Triggers>
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="Foreground" Value="Black"/>
                    <Setter Property="Background" Value="{DynamicResource lightBlueBrush}"/>
                </Trigger>
            </Style.Triggers>
        </Style>
 
        <Style x:Key="LinkButton" TargetType="Button">
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <TextBlock x:Name="tb" Foreground="{TemplateBinding Foreground}">
                        <ContentPresenter />
                        </TextBlock>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="Foreground" TargetName="tb" Value="Blue" />
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" TargetName="tb" Value="Gray" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
 
                </Setter.Value>
            </Setter>
 
        </Style>
 
    </UserControl.Resources>
    <Grid Margin="20">
        <DataGrid x:Name="datagrid" Grid.Row="1" AutoGenerateColumns="False" BorderThickness="0" FontSize="16"
                              RowHeaderWidth="0" BorderBrush="LightGray" CanUserResizeColumns="False" CanUserResizeRows="False" Margin="20 20" Background="White"
                              CanUserSortColumns="False" CanUserReorderColumns="False" CanUserAddRows="False" ColumnHeaderStyle="{DynamicResource dataGridColumnHeaderStyle}"
                              GridLinesVisibility="None" IsReadOnly="True" RowStyle="{StaticResource rowStyle}" CellStyle="{StaticResource cellStyle}"                            
                              LoadingRow="datagrid_LoadingRow">
            <DataGrid.Columns>
                <DataGridTextColumn Width="*" Header="{x:Static str:Resources.strNo}" 
                                        Binding="{Binding Header, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}, Mode=FindAncestor}}"    />
 
                <DataGridTextColumn Width="*" Binding="{Binding Name}" Header="{x:Static str:Resources.strRoleName}" 
                                            />
                <DataGridTextColumn Width="*" Binding="{Binding TypeName}" Header="{x:Static str:Resources.strRoleStatus}" 
                                            />
                <DataGridTextColumn Width="*" Binding="{Binding ModifyName}" Header="{x:Static str:Resources.strOperator}" 
                                            />
                <DataGridTextColumn Width="*" Binding="{Binding ModifyTime}" Header="{x:Static str:Resources.strOperateTime}" 
                                            />
                <DataGridTemplateColumn Header="{x:Static str:Resources.strOperation}" Width="*" >
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                                <Button x:Name="btnEdit" Content="{x:Static str:Resources.strEdit}" Width="80" Height="25" Style="{DynamicResource LinkButton}"
                                                 Tag="{Binding Id}" Foreground="{DynamicResource blueBrush}" Click="btnEdit_Click"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
 
        </DataGrid>
    </Grid>
</UserControl>