質問編集履歴

1

サンプルソースを変更しました

2018/04/17 08:03

投稿

koshiro_
koshiro_

スコア11

test CHANGED
File without changes
test CHANGED
@@ -54,19 +54,361 @@
54
54
 
55
55
  ### 該当のソースコード
56
56
 
57
+ App.xaml
58
+
59
+ ```
60
+
61
+ <Application x:Class="FocusSample.App"
62
+
63
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
64
+
65
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
66
+
67
+ StartupUri="Views\MainWindow.xaml"
68
+
69
+ Startup="Application_Startup">
70
+
71
+ <Application.Resources>
72
+
73
+ <ResourceDictionary>
74
+
75
+ <ResourceDictionary.MergedDictionaries>
76
+
77
+ <ResourceDictionary Source="/FocusSample;component/Views/ButtonTextBox/ButtonTextBox.xaml"/>
78
+
79
+ </ResourceDictionary.MergedDictionaries>
80
+
81
+ </ResourceDictionary>
82
+
83
+ </Application.Resources>
84
+
85
+ </Application>
86
+
87
+
88
+
89
+ ```
90
+
91
+ App.xaml.cs
92
+
93
+ ```C#
94
+
95
+ using System;
96
+
97
+ using System.Collections.Generic;
98
+
99
+ using System.Configuration;
100
+
101
+ using System.Data;
102
+
103
+ using System.Linq;
104
+
105
+ using System.Windows;
106
+
107
+
108
+
109
+ namespace FocusSample {
110
+
111
+ /// <summary>
112
+
113
+ /// App.xaml の相互作用ロジック
114
+
115
+ /// </summary>
116
+
117
+ public partial class App : Application {
118
+
119
+ private void Application_Startup(object sender, StartupEventArgs e) {
120
+
121
+ }
122
+
123
+ }
124
+
125
+ }
126
+
127
+
128
+
129
+ ```
130
+
131
+
132
+
133
+ MainWindow.xaml
134
+
135
+ ```
136
+
137
+ <Window x:Class="FocusSample.Views.MainWindow"
138
+
139
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
140
+
141
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
142
+
143
+ xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
144
+
145
+ xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
146
+
147
+ xmlns:l="http://schemas.livet-mvvm.net/2011/wpf"
148
+
149
+ xmlns:v="clr-namespace:FocusSample.Views"
150
+
151
+ Title="MainWindow" Height="350" Width="525"
152
+
153
+ xmlns:local="clr-namespace:FocusSample.Views.ButtonTextBox">
154
+
155
+
156
+
157
+ <Grid>
158
+
159
+ <Grid.RowDefinitions>
160
+
161
+ <RowDefinition />
162
+
163
+ <RowDefinition />
164
+
165
+ <RowDefinition />
166
+
167
+ </Grid.RowDefinitions>
168
+
169
+
170
+
171
+ <TextBox Height="30"/>
172
+
173
+ <local:ButtonTextBox Grid.Row="1" Focusable="True" Height="30"/>
174
+
175
+ <TextBox Grid.Row="2" Height="30"/>
176
+
177
+
178
+
179
+ </Grid>
180
+
181
+ </Window>
182
+
183
+
184
+
185
+ ```
186
+
187
+ MainWindow.xaml.cs
188
+
189
+ ```C#
190
+
191
+ using System;
192
+
193
+ using System.Collections.Generic;
194
+
195
+ using System.Linq;
196
+
197
+ using System.Text;
198
+
199
+ using System.Windows;
200
+
201
+ using System.Windows.Controls;
202
+
203
+ using System.Windows.Data;
204
+
205
+ using System.Windows.Documents;
206
+
207
+ using System.Windows.Input;
208
+
209
+ using System.Windows.Media;
210
+
211
+ using System.Windows.Media.Imaging;
212
+
213
+ using System.Windows.Navigation;
214
+
215
+ using System.Windows.Shapes;
216
+
217
+
218
+
219
+ namespace FocusSample.Views {
220
+
221
+ /// <summary>
222
+
223
+ /// MainWindow.xaml の相互作用ロジック
224
+
225
+ /// </summary>
226
+
227
+ public partial class MainWindow : Window {
228
+
229
+ public MainWindow() {
230
+
231
+ InitializeComponent();
232
+
233
+ }
234
+
235
+ }
236
+
237
+ }
238
+
239
+ ```
240
+
241
+ ButtonTextBox.cs
242
+
243
+ ```C#
244
+
245
+ using System;
246
+
247
+ using System.Collections.Generic;
248
+
249
+ using System.Linq;
250
+
251
+ using System.Text;
252
+
253
+ using System.Windows;
254
+
255
+ using System.Windows.Controls;
256
+
257
+ using System.Windows.Data;
258
+
259
+ using System.Windows.Documents;
260
+
261
+ using System.Windows.Input;
262
+
263
+ using System.Windows.Media;
264
+
265
+ using System.Windows.Media.Imaging;
266
+
267
+ using System.Windows.Navigation;
268
+
269
+ using System.Windows.Shapes;
270
+
271
+
272
+
273
+ namespace FocusSample.Views.ButtonTextBox {
274
+
275
+ public class ButtonTextBox : TextBox {
276
+
277
+ /// <summary>
278
+
279
+ /// コンストラクタ
280
+
281
+ /// </summary>
282
+
283
+ static ButtonTextBox() {
284
+
285
+ DefaultStyleKeyProperty.OverrideMetadata(typeof(ButtonTextBox), new FrameworkPropertyMetadata(typeof(ButtonTextBox)));
286
+
287
+ }
288
+
289
+
290
+
291
+
292
+
293
+ /// <summary>
294
+
295
+ /// ボタンのキャプション
296
+
297
+ /// </summary>
298
+
299
+ public string ButtonContent {
300
+
301
+ get { return (string)GetValue(ButtonContentProperty); }
302
+
303
+ set { SetValue(ButtonContentProperty, value); }
304
+
305
+ }
306
+
307
+
308
+
309
+ public static readonly DependencyProperty ButtonContentProperty =
310
+
311
+ DependencyProperty.Register("ButtonContent", typeof(string), typeof(ButtonTextBox), new UIPropertyMetadata(string.Empty));
312
+
313
+
314
+
315
+
316
+
317
+ /// <summary>
318
+
319
+ /// ボタンの押されたときのコマンド
320
+
321
+ /// </summary>
322
+
323
+ public ICommand Command {
324
+
325
+ get { return (ICommand)GetValue(CommandProperty); }
326
+
327
+ set { SetValue(CommandProperty, value); }
328
+
329
+ }
330
+
331
+
332
+
333
+ // Using a DependencyProperty as the backing store for Command. This enables animation, styling, binding, etc...
334
+
335
+ public static readonly DependencyProperty CommandProperty =
336
+
337
+ DependencyProperty.Register("Command", typeof(ICommand), typeof(ButtonTextBox));
338
+
339
+
340
+
341
+
342
+
343
+
344
+
345
+ /// <summary>
346
+
347
+ /// コマンパラメータ
348
+
349
+ /// </summary>
350
+
351
+ public object CommandParameter {
352
+
353
+ get { return (object)GetValue(CommandParameterProperty); }
354
+
355
+ set { SetValue(CommandParameterProperty, value); }
356
+
357
+ }
358
+
359
+
360
+
361
+ // Using a DependencyProperty as the backing store for CommandParameter. This enables animation, styling, binding, etc...
362
+
363
+ public static readonly DependencyProperty CommandParameterProperty =
364
+
365
+ DependencyProperty.Register("CommandParameter", typeof(object), typeof(ButtonTextBox));
366
+
367
+
368
+
369
+
370
+
371
+
372
+
373
+ public bool IsButtonEnabled {
374
+
375
+ get { return (bool)GetValue(IsButtonEnabledProperty); }
376
+
377
+ set { SetValue(IsButtonEnabledProperty, value); }
378
+
379
+ }
380
+
381
+
382
+
383
+ // Using a DependencyProperty as the backing store for IsButtonEnabled. This enables animation, styling, binding, etc...
384
+
385
+ public static readonly DependencyProperty IsButtonEnabledProperty =
386
+
387
+ DependencyProperty.Register("IsButtonEnabled", typeof(bool), typeof(ButtonTextBox), new UIPropertyMetadata(true));
388
+
389
+
390
+
391
+
392
+
393
+ }
394
+
395
+ }
396
+
397
+
398
+
399
+
400
+
401
+ ```
402
+
57
403
  ButtonTextBox.xaml
58
404
 
59
- ```
405
+ ```C#
60
-
61
- <ResourceDictionary
406
+
62
-
63
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
407
+ <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
64
-
408
+
65
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
409
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
66
-
410
+
67
- xmlns:local="clr-namespace:CustomControls">
411
+ xmlns:local="clr-namespace:FocusSample.Views.ButtonTextBox">
68
-
69
-
70
412
 
71
413
  <Style TargetType="{x:Type local:ButtonTextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
72
414
 
@@ -74,7 +416,7 @@
74
416
 
75
417
  <Setter.Value>
76
418
 
77
- <ControlTemplate TargetType="{x:Type local:CusButtonTextBox}">
419
+ <ControlTemplate TargetType="{x:Type local:ButtonTextBox}">
78
420
 
79
421
  <Border Background="{TemplateBinding Background}"
80
422
 
@@ -136,76 +478,6 @@
136
478
 
137
479
  ```
138
480
 
139
- ButtonTextBox.cs
140
-
141
- ```C#
142
-
143
- using System;
144
-
145
- using System.Collections.Generic;
146
-
147
- using System.Linq;
148
-
149
- using System.Text;
150
-
151
- using System.Windows;
152
-
153
- using System.Windows.Controls;
154
-
155
- using System.Windows.Data;
156
-
157
- using System.Windows.Documents;
158
-
159
- using System.Windows.Input;
160
-
161
- using System.Windows.Media;
162
-
163
- using System.Windows.Media.Imaging;
164
-
165
- using System.Windows.Navigation;
166
-
167
- using System.Windows.Shapes;
168
-
169
-
170
-
171
- namespace CustomControls {
172
-
173
- /// <summary>
174
-
175
- /// テキストボックス+ボタン
176
-
177
- /// </summary>
178
-
179
- public class ButtonTextBox : TextBox {
180
-
181
-
182
-
183
- /// <summary>
184
-
185
- /// コンストラクタ
186
-
187
- /// </summary>
188
-
189
- static ButtonTextBox() {
190
-
191
- DefaultStyleKeyProperty.OverrideMetadata(typeof(ButtonTextBox), new FrameworkPropertyMetadata(typeof(ButtonTextBox)));
192
-
193
- }
194
-
195
-
196
-
197
- #region Button関連のコマンド
198
-
199
- #endregion
200
-
201
- }
202
-
203
- }
204
-
205
-
206
-
207
- ```
208
-
209
481
 
210
482
 
211
483
  ### 補足情報(FW/ツールのバージョンなど)