Skip to content

Commit 70f4408

Browse files
committed
取消标识位
开启修改标志位之后,取消失去焦点更新。会导致在编辑中,并失去焦点并来回后,无法编辑 Fixes #18
1 parent 1a778e9 commit 70f4408

4 files changed

Lines changed: 36 additions & 18 deletions

File tree

demo/Ursa.Demo/Pages/NumericUpDownDemo.axaml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,19 @@
2525
<Style Selector="v|NumericUpDown:invalid">
2626
<Setter Property="Foreground" Value="red" />
2727
</Style>
28-
<!--
28+
29+
<Style Selector="v|NumericUpDown:editing">
30+
<Setter Property="FontSize" Value="15" />
31+
</Style>
32+
2933
<Style Selector="v|NumericUpDown:editing">
30-
<Setter Property="FontSize" Value="12" />
34+
<Style Selector="^ /template/ TextBox#PART_TextBox">
35+
<Setter Property="Foreground" Value="Green" />
36+
</Style>
37+
<Style Selector="^:invalid /template/ TextBox#PART_TextBox">
38+
<Setter Property="Foreground" Value="Red" />
39+
</Style>
3140
</Style>
32-
-->
3341
</UserControl.Styles>
3442

3543
<Grid ColumnDefinitions="350,auto,*" RowDefinitions="auto,*">
@@ -47,6 +55,7 @@
4755
Margin="10"
4856
HorizontalAlignment="Stretch"
4957
>
58+
<!-- IsEnableEditingIndicator="{Binding IsEnableEditingIndicator}" -->
5059
<v:VariableBoxUInt
5160
Name="numd"
5261
Width="{Binding Width}"
@@ -59,7 +68,6 @@
5968
HeaderDoubleTaped="Numd_HeaderDoubleTaped"
6069
IsAllowDrag="{Binding IsAllowDrag}"
6170
IsAllowSpin="{Binding IsAllowSpin}"
62-
IsEnableEditingIndicator="{Binding IsEnableEditingIndicator}"
6371
IsEnabled="{Binding IsEnable}"
6472
IsReadOnly="{Binding IsReadOnly}"
6573
IsShowReadButton="{Binding IsShowReadButton}"
@@ -296,7 +304,7 @@
296304

297305
<CheckBox Content="IsReadOnly" IsChecked="{Binding IsReadOnly}" />
298306
<CheckBox Content="IsUpdateValueWhenLostFocus" IsChecked="{Binding IsUpdateValueWhenLostFocus}" />
299-
<CheckBox Content="IsEnableEditingIndicator" IsChecked="{Binding IsEnableEditingIndicator}" />
307+
<!-- <CheckBox Content="IsEnableEditingIndicator" IsChecked="{Binding IsEnableEditingIndicator}" /> -->
300308
<CheckBox Content="IsShowReadButton" IsChecked="{Binding IsShowReadButton}" />
301309
<CheckBox Content="IsShowWriteButton" IsChecked="{Binding IsShowWriteButton}" />
302310

demo/Ursa.Demo/ViewModels/NumericUpDownDemoViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public partial class NumericUpDownDemoViewModel : ObservableObject
5151

5252
[ObservableProperty] private bool _IsShowReadButton = true;
5353
[ObservableProperty] private bool _IsShowWriteButton = true;
54-
[ObservableProperty] private bool _IsEnableEditingIndicator = true;
54+
// [ObservableProperty] private bool _IsEnableEditingIndicator = true;
5555

5656

5757
uint v = 0;

src/VariableBox/Controls/VariableBox/NumericUpDownBase.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ public bool IsUpdateValueWhenLostFocus
190190

191191
public bool IsEditingValid { get; protected set; }
192192

193+
#if false
193194
public static readonly StyledProperty<bool> IsEditingVisiableProperty =
194195
AvaloniaProperty.Register<NumericUpDown, bool>(nameof(IsEditingVisiable), false);
195196

@@ -202,6 +203,7 @@ public bool IsEditingVisiable
202203
get => GetValue(IsEditingVisiableProperty);
203204
protected set => SetValue(IsEditingVisiableProperty, value && IsEnableEditingIndicator);
204205
}
206+
#endif
205207

206208
public static readonly StyledProperty<bool> IsEditingProperty =
207209
AvaloniaProperty.Register<NumericUpDown, bool>(nameof(IsEditing), false);
@@ -237,12 +239,13 @@ static NumericUpDown()
237239
IsShowReadButtonProperty.Changed.AddClassHandler<NumericUpDown, bool>((o, e) => o.OnReadWriteShowChange(e));
238240
IsShowWriteButtonProperty.Changed.AddClassHandler<NumericUpDown, bool>((o, e) => o.OnReadWriteShowChange(e));
239241

240-
IsEnableEditingIndicatorProperty.Changed.AddClassHandler<NumericUpDown, bool>((o, e) => o.OnIsEnableEditingIndicatorChanged(e));
242+
// IsEnableEditingIndicatorProperty.Changed.AddClassHandler<NumericUpDown, bool>((o, e) => o.OnIsEnableEditingIndicatorChanged(e));
241243
}
242244

243245
private void OnIsEnableEditingIndicatorChanged(AvaloniaPropertyChangedEventArgs<bool> e)
244246
{
245-
IsEditingVisiable = IsEditing && IsEnableEditingIndicator;
247+
// IsEditingVisiable =
248+
// IsEditing && IsEnableEditingIndicator;
246249
}
247250

248251
private void OnReadWriteShowChange(AvaloniaPropertyChangedEventArgs<bool> e)
@@ -367,7 +370,8 @@ private void OnTextBoxTextChanged(object? sender, TextChangedEventArgs e)
367370
{
368371
CheckContextIsChangedAndValid((sender as TextBox).Text, ref ed, ref edv);
369372

370-
IsEditingVisiable = IsEditing = ed;
373+
// IsEditingVisiable =
374+
IsEditing = ed;
371375
IsEditingValid = edv;
372376
UpdatePseudoClasses();
373377
}

src/VariableBox/Controls/VariableBoxNumeric.axaml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@
3333
<ControlTemplate>
3434
<!-- BorderBrush="LightGray" -->
3535
<Border
36+
Name="PART_Border"
3637
Margin="{TemplateBinding Margin}"
38+
Background="{TemplateBinding Background}"
3739
BorderBrush="{TemplateBinding BorderBrush}"
3840
BorderThickness="1"
39-
Background="{TemplateBinding Background}"
4041
CornerRadius="{DynamicResource ControlCornerRadius}"
4142
>
4243
<Grid Background="Transparent" ColumnDefinitions="*,auto">
@@ -101,15 +102,15 @@
101102
Theme="{StaticResource InputClearButton}"
102103
/>
103104
-->
104-
<Label
105+
<!-- <Label
105106
Name="PART_Id_IsEditing"
106107
Margin="2,1,2,0"
107108
Background="Transparent"
108109
Content="*"
109110
Foreground="Green"
110111
IsHitTestVisible="False"
111112
IsVisible="{TemplateBinding IsEditingVisiable}"
112-
/>
113+
/>-->
113114
</Panel>
114115
</ButtonSpinner>
115116

@@ -185,7 +186,7 @@
185186
<Setter Property="Background" Value="Transparent" />
186187
<Setter Property="Opacity" Value="0.5" />
187188
</Style>
188-
</Style> -->
189+
</Style>-->
189190
<Style Selector="^.clearButton, ^.ClearButton">
190191
<Style Selector="^[IsReadOnly=False]:focus /template/ Button#PART_ClearButton">
191192
<Setter Property="IsVisible" Value="True" />
@@ -200,12 +201,17 @@
200201
</Style>
201202

202203
<!-- IsEditingValid -->
203-
<Style Selector="^:invalid /template/ Label#PART_Id_IsEditing">
204-
<Setter Property="Foreground" Value="Red" />
205-
</Style>
206-
<Style Selector="^:invalid /template/ Label#PART_Id_IsEditing">
207-
<Setter Property="Foreground" Value="Red" />
204+
<!--
205+
<Style Selector="^:editing">
206+
<Style Selector="^ /template/ TextBox#PART_TextBox">
207+
<Setter Property="Foreground" Value="Green" />
208+
</Style>
209+
<Style Selector="^:invalid /template/ TextBox#PART_TextBox">
210+
<Setter Property="Foreground" Value="Red" />
211+
</Style>
208212
</Style>
213+
-->
214+
209215
<!--
210216
<Style Selector="^[IsEditingValid=true] /template/ Label#PART_Id_IsEditing">
211217
<Setter Property="Foreground" Value="Green" />

0 commit comments

Comments
 (0)