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
<UserControl x:Class="XHandler.View.Liquids.CalibrationParam"
             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.Liquids"
             xmlns:str="clr-namespace:XHandler.Properties"
             xmlns:ctrls="clr-namespace:XHandler.Controls"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    
    <UserControl.Resources>
        <Style TargetType="TextBlock" x:Key="centerAlignmentStyle">
            <Setter Property="Foreground" Value="Black"/>
            <Setter Property="FontSize" Value="16"/>
            <Setter Property="HorizontalAlignment" Value="Center"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="TextWrapping" Value="Wrap"/>
        </Style>
 
        <!--DataGrid样式-->
            <Style TargetType="DataGrid">
                <!--网格线颜色-->
                <Setter Property="CanUserResizeColumns" Value="false"/>
                <Setter Property="Background" Value="White" />
                <Setter Property="BorderBrush" Value="LightGray" />
                <Setter Property="HorizontalGridLinesBrush">
                    <Setter.Value>
                    <SolidColorBrush Color="LightGray"/>
                    </Setter.Value>
                </Setter>
                <Setter Property="VerticalGridLinesBrush">
                    <Setter.Value>
                    <SolidColorBrush Color="LightGray"/>
                    </Setter.Value>
                </Setter>
            </Style>
 
            <!--标题栏样式-->
            <Style 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="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="DataGridColumnHeader">
                            <Border x:Name="BackgroundBorder" BorderThickness="0,1,0,1" 
                             BorderBrush="LightGray" 
                              Width="Auto">
                                <Grid >
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>
                                    <ContentPresenter  Margin="0,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                                <Rectangle Width="1" Fill="LightGray" HorizontalAlignment="Right" Grid.ColumnSpan="1" />
                                </Grid>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Setter Property="Height" Value="60"/>
            </Style>
        
            <!--行样式触发-->
            <!--背景色改变必须先设置cellStyle 因为cellStyle会覆盖rowStyle样式-->
            <Style  TargetType="DataGridRow">
                <Setter Property="Background" Value="White" />
                <Setter Property="Height" Value="60"/>
            <Setter Property="FontSize" Value="16" />
            <Setter Property="Foreground" Value="Black" />
                <Style.Triggers>
                    <!--隔行换色-->
                    <!--<Trigger Property="AlternationIndex" Value="0" >
                        <Setter Property="Background" Value="#e7e7e7" />
                    </Trigger>
                    <Trigger Property="AlternationIndex" Value="1" >
                        <Setter Property="Background" Value="#f2f2f2" />
                    </Trigger>-->
 
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Background" Value="LightGray"/>
                        <!--<Setter Property="Foreground" Value="White"/>-->
                    </Trigger>
 
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="Background" Value="{DynamicResource lightBlueBrush}"/>
 
                </Trigger>
                </Style.Triggers>
            </Style>
 
            <!--单元格样式触发-->
            <Style TargetType="DataGridCell">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="DataGridCell">
                            <TextBlock TextAlignment="Center" VerticalAlignment="Center"  >
                           <ContentPresenter />
                            </TextBlock>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="Foreground" Value="Black"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
 
        <Style x:Key="CellEditStyle" TargetType="{x:Type TextBox}">
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="Padding" Value="0"/>
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="ToolTip"
                        Value="{Binding RelativeSource={RelativeSource Self},
                                Path=(Validation.Errors)[0].ErrorContent}"/>
                </Trigger>
            </Style.Triggers>
        </Style>
        <Style x:Key="CellNonEditStyle" TargetType="{x:Type TextBlock}">
 
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="ToolTip"
                        Value="{Binding RelativeSource={RelativeSource Self},
                                Path=(Validation.Errors)[0].ErrorContent}"/>
                </Trigger>
            </Style.Triggers>
        </Style>
 
        <Style x:Key="CellViewStyle" TargetType="{x:Type Label}" BasedOn="{StaticResource {x:Type Label}}">
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="ToolTip"
                        Value="{Binding RelativeSource={RelativeSource Self},
                                Path=(Validation.Errors)[0].ErrorContent}"/>
                    <Setter Property="BorderBrush" Value="Red" />
                    <Setter Property="BorderThickness" Value="1" />
                </Trigger>
            </Style.Triggers>
        </Style>
 
        <Style x:Key="eidtTextBoxStyle" TargetType="TextBox">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate >
                        <Grid>
                            <Border x:Name="BackBorder" SnapsToDevicePixels="true" Background="{TemplateBinding Background}"
                            BorderThickness="0" BorderBrush="{TemplateBinding BorderBrush}">
                                <ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                            </Border>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <!--<Trigger Property="IsFocused" Value="True" >
                                <Setter Property="Background" TargetName="BackBorder" Value="#FFE5E6EB"/>
                            </Trigger>-->
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="TextBox.Foreground" Value="Gray"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
 
    <Grid Name="gdContent">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="60"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" x:Name="calibrationWidth"/>
        </Grid.ColumnDefinitions>
 
        <DataGrid x:Name="dg" AutoGenerateColumns="False"  VerticalAlignment="Top" HorizontalAlignment="Center" BorderThickness="1 0 0 0"
                  CanUserSortColumns="False" Margin="20 20" Grid.Row="0" Grid.Column="0" 
                  CanUserResizeColumns="False" CanUserResizeRows="False" 
                  CanUserReorderColumns="False" RowHeaderWidth="0" CanUserAddRows="False" 
                  BeginningEdit="dg_BeginningEdit" CellEditEnding="dg_CellEditEnding" Width="680">
            <DataGrid.Columns>
                <DataGridTemplateColumn Width="5*" Header="{x:Static str:Resources.strTargetVolumn}" >
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Label Content="{Binding liquid_target_volume}" Tag="{Binding liquidaccuracy_Id}" Foreground="Black" ToolTip="双击编辑"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <TextBox x:Name="tbTarget" Text="{Binding Path=liquid_target_volume}" 
                                     Style="{DynamicResource eidtTextBoxStyle}" Tag="{Binding liquidaccuracy_Id}" Width="200" Height="50" FontSize="16" HorizontalContentAlignment="Center"
                                     VerticalContentAlignment="Center"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>
 
                <DataGridTemplateColumn Width="5*" Header="{x:Static str:Resources.strCorrectVolumn}" >
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Label Content="{Binding liquid_Real_volume}" Tag="{Binding liquidaccuracy_Id}" Foreground="Black" ToolTip="双击编辑"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <TextBox x:Name="tbTargetReal" Text="{Binding Path=liquid_Real_volume}" 
                                     Style="{DynamicResource eidtTextBoxStyle}" Tag="{Binding liquidaccuracy_Id}" Width="200" Height="50" FontSize="16" HorizontalContentAlignment="Center"
                                     VerticalContentAlignment="Center"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
 
        <Button Grid.Row="1" Grid.Column="0" x:Name="btnDelete" Content="{x:Static str:Resources.btnRemove}" Width="80" Height="40" VerticalContentAlignment="Center"
                HorizontalAlignment="Right" VerticalAlignment="Center" Margin="120 0" FontSize="16" Style="{DynamicResource BlueButtonStyle}"
                Background="{DynamicResource blueBrush}" Click="btnDelete_Click"/>
 
        <Button Grid.Row="1" Grid.Column="0" x:Name="btnAdd" Content="{x:Static str:Resources.btnAdd}" Width="80" Height="40" VerticalContentAlignment="Center"
                HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0 0 20 0" FontSize="16" Style="{DynamicResource BlueButtonStyle}"
                Background="{DynamicResource blueBrush}" Click="btnAdd_Click"/>
 
        <TextBlock Grid.Row="1" Grid.Column="0" x:Name="lnError" Text="{Binding  ElementName=dg,Path=(Validation.Errors)[0].ErrorContent}" Foreground="Red" FontSize="16" 
                   VerticalAlignment="Center" HorizontalAlignment="Left" Margin="50 5 5 5"/>
    </Grid>
</UserControl>