回答編集履歴
1
見直しキャンペーン中
test
CHANGED
@@ -1,157 +1,79 @@
|
|
1
1
|
結構悩ましいですね(`double`なとこも地味にいじわる^^;
|
2
|
-
|
3
2
|
takapi_csさんの回答が真っ当という気がしますが、手抜きならこんなのもあるかなと。
|
4
3
|
|
5
|
-
|
6
|
-
|
7
4
|
コンバータは適当です^^; お好きな実装をどうぞ。
|
8
|
-
|
9
5
|
`KeepTextBoxDisplaySynchronizedWithTextProperty`の影響範囲はよくわかりません(使ったことないので^^;
|
10
6
|
|
11
|
-
|
12
|
-
|
13
|
-
```x
|
7
|
+
```xml
|
14
|
-
|
15
8
|
<Window
|
16
|
-
|
17
9
|
x:Class="Questions295331.MainWindow"
|
18
|
-
|
19
10
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
20
|
-
|
21
11
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
22
|
-
|
23
12
|
xmlns:local="clr-namespace:Questions295331"
|
24
|
-
|
25
13
|
Width="800"
|
26
|
-
|
27
14
|
Height="450">
|
28
|
-
|
29
15
|
<StackPanel>
|
30
|
-
|
31
16
|
<TextBox
|
32
|
-
|
33
17
|
x:Name="textBox"
|
34
|
-
|
35
18
|
Width="100"
|
36
|
-
|
37
19
|
Margin="10"
|
38
|
-
|
39
20
|
Text="{Binding ValidateParameter.Value, UpdateSourceTrigger=PropertyChanged}" />
|
40
|
-
|
41
21
|
<Button
|
42
|
-
|
43
22
|
Width="100"
|
44
|
-
|
45
23
|
Command="{Binding ValidCommand}"
|
46
|
-
|
47
24
|
Content="Valid"
|
48
|
-
|
49
25
|
IsEnabled="{Binding (Validation.HasError), Converter={local:InverseBooleanConverter}, ElementName=textBox}" />
|
50
|
-
|
51
26
|
</StackPanel>
|
52
|
-
|
53
27
|
</Window>
|
54
|
-
|
55
28
|
```
|
56
29
|
|
57
|
-
|
58
|
-
|
59
|
-
```
|
30
|
+
```cs
|
60
|
-
|
61
31
|
using System;
|
62
|
-
|
63
32
|
using System.ComponentModel.DataAnnotations;
|
64
|
-
|
65
33
|
using System.Diagnostics;
|
66
|
-
|
67
34
|
using System.Globalization;
|
68
|
-
|
69
35
|
using System.Windows;
|
70
|
-
|
71
36
|
using System.Windows.Data;
|
72
|
-
|
73
37
|
using System.Windows.Markup;
|
74
|
-
|
75
38
|
using Reactive.Bindings;
|
76
39
|
|
77
|
-
|
78
|
-
|
79
40
|
namespace Questions295331
|
80
|
-
|
81
41
|
{
|
82
|
-
|
83
42
|
public class InverseBooleanConverter : MarkupExtension, IValueConverter
|
84
|
-
|
85
43
|
{
|
86
|
-
|
87
44
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
88
|
-
|
89
45
|
=> !(bool)value;
|
90
|
-
|
91
46
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
92
|
-
|
93
47
|
=> throw new NotImplementedException();
|
94
|
-
|
95
48
|
public override object ProvideValue(IServiceProvider serviceProvider) => this;
|
96
|
-
|
97
49
|
}
|
98
50
|
|
99
|
-
|
100
|
-
|
101
51
|
class MainWindowsViewModel
|
102
|
-
|
103
52
|
{
|
104
|
-
|
105
53
|
[Range(0, 100d)]
|
106
|
-
|
107
54
|
public ReactiveProperty<double> ValidateParameter { get; }
|
108
|
-
|
109
|
-
|
110
55
|
|
111
56
|
public ReactiveCommand ValidCommand { get; }
|
112
57
|
|
113
|
-
|
114
|
-
|
115
58
|
public MainWindowsViewModel()
|
116
|
-
|
117
59
|
{
|
118
|
-
|
119
60
|
ValidateParameter = new ReactiveProperty<double>()
|
120
|
-
|
121
61
|
.SetValidateAttribute(() => ValidateParameter);
|
122
62
|
|
123
|
-
|
124
|
-
|
125
63
|
ValidCommand = new ReactiveCommand()
|
126
|
-
|
127
64
|
.WithSubscribe(() => Debug.WriteLine(ValidateParameter.Value));
|
128
|
-
|
129
65
|
}
|
130
|
-
|
131
66
|
}
|
132
67
|
|
133
|
-
|
134
|
-
|
135
68
|
public partial class MainWindow : Window
|
136
|
-
|
137
69
|
{
|
138
|
-
|
139
70
|
public MainWindow()
|
140
|
-
|
141
71
|
{
|
142
|
-
|
143
72
|
FrameworkCompatibilityPreferences.KeepTextBoxDisplaySynchronizedWithTextProperty = false;
|
144
73
|
|
145
|
-
|
146
|
-
|
147
74
|
InitializeComponent();
|
148
|
-
|
149
75
|
DataContext = new MainWindowsViewModel();
|
150
|
-
|
151
76
|
}
|
152
|
-
|
153
77
|
}
|
154
|
-
|
155
78
|
}
|
156
|
-
|
157
79
|
```
|