質問編集履歴

1

コードの追加

2018/09/12 00:14

投稿

nekome4
nekome4

スコア24

test CHANGED
File without changes
test CHANGED
@@ -26,6 +26,68 @@
26
26
 
27
27
 
28
28
 
29
+ コードにすると以下のようになっています。
30
+
31
+
32
+
33
+ [CustomControl1.cs の一部]
34
+
35
+ ```C#
36
+
37
+ public class CustomControl1 : TextBox
38
+
39
+ {
40
+
41
+ static CustomControl1()
42
+
43
+ {     
44
+
45
+ DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl1), new FrameworkPropertyMetadata(typeof(CustomControl1)));
46
+
47
+ }
48
+
49
+ }
50
+
51
+ ```
52
+
53
+
54
+
55
+ こちらもBasedOnを指定しただけです。
56
+
57
+ [Generic.xaml の一部]
58
+
59
+ ```xaml
60
+
61
+ <Style TargetType="{x:Type local:CustomControl1}" BasedOn="{StaticResource {x:Type TextBox}}">
62
+
63
+ <Setter Property="Template">
64
+
65
+ <Setter.Value>
66
+
67
+ <ControlTemplate TargetType="{x:Type local:CustomControl1}">
68
+
69
+ <Border Background="{TemplateBinding Background}"
70
+
71
+ BorderBrush="{TemplateBinding BorderBrush}"
72
+
73
+ BorderThickness="{TemplateBinding BorderThickness}">
74
+
75
+ </Border>
76
+
77
+ </ControlTemplate>
78
+
79
+ </Setter.Value>
80
+
81
+ </Setter>
82
+
83
+ </Style>
84
+
85
+ ```
86
+
87
+
88
+
89
+
90
+
29
91
  元々カスタムコントロールは上記手順を踏まず、普通に.csファイル単体を作成して記述していました。
30
92
 
31
93
  その場合は普通に入力編集などできていたのでそれでよいのかと思いましたがこの方法は間違っているのでしょうか?