回答編集履歴
4
見直しキャンペーン中
answer
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
カスタムコントロールを作ってください。
|
2
|
-
|
2
|
+
UWP向けの記事があんまり見つからないので、WPFで調べてください ~~(試してないですが流れは同じはずです^^;~~
|
3
3
|
|
4
4
|
---
|
5
5
|
|
6
|
-
|
6
|
+
UWPでは「**テンプレート コントロール**」という用語になっているようです(コントロールテンプレートだとまた別の意味になってしまいます)
|
7
7
|

|
8
8
|
右の説明やファイル名はカスタムコントロールなのに。。。
|
9
9
|
|
@@ -26,7 +26,7 @@
|
|
26
26
|
[WPF4.5入門 その54 「カスタムコントロール」 - かずきのBlog@hatena](https://blog.okazuki.jp/entry/2014/09/08/221209)
|
27
27
|
|
28
28
|
|
29
|
-
### App1プロジェクト
|
29
|
+
##### App1プロジェクト
|
30
30
|
```xml:MainPage.xaml
|
31
31
|
<Page
|
32
32
|
x:Class="App1.MainPage"
|
@@ -64,7 +64,7 @@
|
|
64
64
|
</Page>
|
65
65
|
```
|
66
66
|
|
67
|
-
### ClassLibrary1プロジェクト
|
67
|
+
##### ClassLibrary1プロジェクト
|
68
68
|
```xml:Generic.xaml
|
69
69
|
<ResourceDictionary
|
70
70
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
@@ -157,4 +157,5 @@
|
|
157
157
|
}
|
158
158
|
```
|
159
159
|
他は初期状態
|
160
|
+
|
160
161
|

|
3
見直しキャンペーン中
answer
CHANGED
@@ -1,161 +1,160 @@
|
|
1
|
-
カスタムコントロールを作ってください。
|
2
|
-
`UWP`向けの記事があんまり見つからないので、`WPF`で調べてください(試してないですが流れは同じはずです^^;
|
3
|
-
|
4
|
-
---
|
5
|
-
|
6
|
-
`UWP`では「**テンプレート コントロール**」という用語になっているようです(コントロールテンプレートだとまた別の意味になってしまいます)
|
7
|
-

|
8
|
-
右の説明やファイル名はカスタムコントロールなのに。。。
|
9
|
-
|
10
|
-
[Windows ストア アプリでページ間で共通の見た目を簡単に作りたい - かずきのBlog@hatena](https://blog.okazuki.jp/entry/2014/01/09/003357)
|
11
|
-
ちょっと例を書いてみようと思ったのですが、↑で十分でしょうか。
|
12
|
-
|
13
|
-
[C++/WinRT による XAML カスタム (テンプレート化) コントロール - UWP applications | Microsoft Docs](https://docs.microsoft.com/ja-jp/windows/uwp/cpp-and-winrt-apis/xaml-cust-ctrl)
|
14
|
-
公式での説明はC++での例しか見つけられませんでした。
|
15
|
-
|
16
|
-
---
|
17
|
-
|
18
|
-
> 見た目や処理が同じPageが多々でてきますので、
|
19
|
-
> なにかベースになるものを用意し、
|
20
|
-
> そこから派生して、
|
21
|
-
> オリジナルのコンポーネントを作成
|
22
|
-
|
23
|
-
には全く役に立ちませんが、テンプレート コントロールの検証です。
|
24
|
-
|
25
|
-
なんかネタが思いつかなかったので、またかずきさんのお借りしました^^;
|
26
|
-
[WPF4.5入門 その54 「カスタムコントロール」 - かずきのBlog@hatena](https://blog.okazuki.jp/entry/2014/09/08/221209)
|
27
|
-
|
28
|
-
|
29
|
-
App1プロジェクト
|
30
|
-
```xaml
|
31
|
-
<Page
|
32
|
-
x:Class="App1.MainPage"
|
33
|
-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
34
|
-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
35
|
-
xmlns:classLibrary1="using:ClassLibrary1"
|
36
|
-
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
37
|
-
|
38
|
-
<StackPanel>
|
39
|
-
<classLibrary1:NumericUpDown
|
40
|
-
HorizontalAlignment="Left"
|
41
|
-
Background="LightBlue"
|
42
|
-
BorderBrush="Green"
|
43
|
-
BorderThickness="2"
|
44
|
-
FontSize="36"
|
45
|
-
Foreground="Red"
|
46
|
-
Value="100" />
|
47
|
-
|
48
|
-
<classLibrary1:NumericUpDown HorizontalAlignment="Left">
|
49
|
-
<classLibrary1:NumericUpDown.Template>
|
50
|
-
<ControlTemplate TargetType="classLibrary1:NumericUpDown">
|
51
|
-
<StackPanel>
|
52
|
-
<RepeatButton x:Name="PART_UpButton" HorizontalAlignment="Stretch">
|
53
|
-
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="" />
|
54
|
-
</RepeatButton>
|
55
|
-
<TextBlock HorizontalAlignment="Center" Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}}" />
|
56
|
-
<RepeatButton x:Name="PART_DownButton" HorizontalAlignment="Stretch">
|
57
|
-
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="" />
|
58
|
-
</RepeatButton>
|
59
|
-
</StackPanel>
|
60
|
-
</ControlTemplate>
|
61
|
-
</classLibrary1:NumericUpDown.Template>
|
62
|
-
</classLibrary1:NumericUpDown>
|
63
|
-
</StackPanel>
|
64
|
-
</Page>
|
65
|
-
```
|
66
|
-
|
67
|
-
ClassLibrary1プロジェクト
|
68
|
-
```xaml
|
69
|
-
<ResourceDictionary
|
70
|
-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
71
|
-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
72
|
-
xmlns:local="using:ClassLibrary1">
|
73
|
-
<Style TargetType="local:NumericUpDown">
|
74
|
-
<Setter Property="Template">
|
75
|
-
<Setter.Value>
|
76
|
-
<ControlTemplate TargetType="local:NumericUpDown">
|
77
|
-
<Border
|
78
|
-
Background="{TemplateBinding Background}"
|
79
|
-
BorderBrush="{TemplateBinding BorderBrush}"
|
80
|
-
BorderThickness="{TemplateBinding BorderThickness}">
|
81
|
-
<Grid>
|
82
|
-
<Grid.RowDefinitions>
|
83
|
-
<RowDefinition />
|
84
|
-
<RowDefinition />
|
85
|
-
</Grid.RowDefinitions>
|
86
|
-
<Grid.ColumnDefinitions>
|
87
|
-
<ColumnDefinition />
|
88
|
-
<ColumnDefinition />
|
89
|
-
</Grid.ColumnDefinitions>
|
90
|
-
<TextBlock
|
91
|
-
Grid.RowSpan="2"
|
92
|
-
VerticalAlignment="Center"
|
93
|
-
Foreground="{TemplateBinding Foreground}"
|
94
|
-
Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}}"
|
95
|
-
TextWrapping="Wrap" />
|
96
|
-
<RepeatButton
|
97
|
-
x:Name="PART_UpButton"
|
98
|
-
Grid.Column="1"
|
99
|
-
HorizontalAlignment="Stretch"
|
100
|
-
Content="Up" />
|
101
|
-
<RepeatButton
|
102
|
-
x:Name="PART_DownButton"
|
103
|
-
Grid.Row="1"
|
104
|
-
Grid.Column="1"
|
105
|
-
HorizontalAlignment="Stretch"
|
106
|
-
Content="Down" />
|
107
|
-
</Grid>
|
108
|
-
</Border>
|
109
|
-
</ControlTemplate>
|
110
|
-
</Setter.Value>
|
111
|
-
</Setter>
|
112
|
-
</Style>
|
113
|
-
</ResourceDictionary>
|
114
|
-
```
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
using Windows.UI.Xaml;
|
119
|
-
using Windows.UI.Xaml.Controls;
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
private RepeatButton
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
private void
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
if(
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
if(
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
他は初期状態
|
1
|
+
カスタムコントロールを作ってください。
|
2
|
+
`UWP`向けの記事があんまり見つからないので、`WPF`で調べてください(試してないですが流れは同じはずです^^;
|
3
|
+
|
4
|
+
---
|
5
|
+
|
6
|
+
`UWP`では「**テンプレート コントロール**」という用語になっているようです(コントロールテンプレートだとまた別の意味になってしまいます)
|
7
|
+

|
8
|
+
右の説明やファイル名はカスタムコントロールなのに。。。
|
9
|
+
|
10
|
+
[Windows ストア アプリでページ間で共通の見た目を簡単に作りたい - かずきのBlog@hatena](https://blog.okazuki.jp/entry/2014/01/09/003357)
|
11
|
+
ちょっと例を書いてみようと思ったのですが、↑で十分でしょうか。
|
12
|
+
|
13
|
+
[C++/WinRT による XAML カスタム (テンプレート化) コントロール - UWP applications | Microsoft Docs](https://docs.microsoft.com/ja-jp/windows/uwp/cpp-and-winrt-apis/xaml-cust-ctrl)
|
14
|
+
公式での説明はC++での例しか見つけられませんでした。
|
15
|
+
|
16
|
+
---
|
17
|
+
|
18
|
+
> 見た目や処理が同じPageが多々でてきますので、
|
19
|
+
> なにかベースになるものを用意し、
|
20
|
+
> そこから派生して、
|
21
|
+
> オリジナルのコンポーネントを作成
|
22
|
+
|
23
|
+
には全く役に立ちませんが、テンプレート コントロールの検証です。
|
24
|
+
|
25
|
+
なんかネタが思いつかなかったので、またかずきさんのお借りしました^^;
|
26
|
+
[WPF4.5入門 その54 「カスタムコントロール」 - かずきのBlog@hatena](https://blog.okazuki.jp/entry/2014/09/08/221209)
|
27
|
+
|
28
|
+
|
29
|
+
### App1プロジェクト
|
30
|
+
```xml:MainPage.xaml
|
31
|
+
<Page
|
32
|
+
x:Class="App1.MainPage"
|
33
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
34
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
35
|
+
xmlns:classLibrary1="using:ClassLibrary1"
|
36
|
+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
37
|
+
|
38
|
+
<StackPanel>
|
39
|
+
<classLibrary1:NumericUpDown
|
40
|
+
HorizontalAlignment="Left"
|
41
|
+
Background="LightBlue"
|
42
|
+
BorderBrush="Green"
|
43
|
+
BorderThickness="2"
|
44
|
+
FontSize="36"
|
45
|
+
Foreground="Red"
|
46
|
+
Value="100" />
|
47
|
+
|
48
|
+
<classLibrary1:NumericUpDown HorizontalAlignment="Left">
|
49
|
+
<classLibrary1:NumericUpDown.Template>
|
50
|
+
<ControlTemplate TargetType="classLibrary1:NumericUpDown">
|
51
|
+
<StackPanel>
|
52
|
+
<RepeatButton x:Name="PART_UpButton" HorizontalAlignment="Stretch">
|
53
|
+
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="" />
|
54
|
+
</RepeatButton>
|
55
|
+
<TextBlock HorizontalAlignment="Center" Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}}" />
|
56
|
+
<RepeatButton x:Name="PART_DownButton" HorizontalAlignment="Stretch">
|
57
|
+
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="" />
|
58
|
+
</RepeatButton>
|
59
|
+
</StackPanel>
|
60
|
+
</ControlTemplate>
|
61
|
+
</classLibrary1:NumericUpDown.Template>
|
62
|
+
</classLibrary1:NumericUpDown>
|
63
|
+
</StackPanel>
|
64
|
+
</Page>
|
65
|
+
```
|
66
|
+
|
67
|
+
### ClassLibrary1プロジェクト
|
68
|
+
```xml:Generic.xaml
|
69
|
+
<ResourceDictionary
|
70
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
71
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
72
|
+
xmlns:local="using:ClassLibrary1">
|
73
|
+
<Style TargetType="local:NumericUpDown">
|
74
|
+
<Setter Property="Template">
|
75
|
+
<Setter.Value>
|
76
|
+
<ControlTemplate TargetType="local:NumericUpDown">
|
77
|
+
<Border
|
78
|
+
Background="{TemplateBinding Background}"
|
79
|
+
BorderBrush="{TemplateBinding BorderBrush}"
|
80
|
+
BorderThickness="{TemplateBinding BorderThickness}">
|
81
|
+
<Grid>
|
82
|
+
<Grid.RowDefinitions>
|
83
|
+
<RowDefinition />
|
84
|
+
<RowDefinition />
|
85
|
+
</Grid.RowDefinitions>
|
86
|
+
<Grid.ColumnDefinitions>
|
87
|
+
<ColumnDefinition />
|
88
|
+
<ColumnDefinition />
|
89
|
+
</Grid.ColumnDefinitions>
|
90
|
+
<TextBlock
|
91
|
+
Grid.RowSpan="2"
|
92
|
+
VerticalAlignment="Center"
|
93
|
+
Foreground="{TemplateBinding Foreground}"
|
94
|
+
Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}}"
|
95
|
+
TextWrapping="Wrap" />
|
96
|
+
<RepeatButton
|
97
|
+
x:Name="PART_UpButton"
|
98
|
+
Grid.Column="1"
|
99
|
+
HorizontalAlignment="Stretch"
|
100
|
+
Content="Up" />
|
101
|
+
<RepeatButton
|
102
|
+
x:Name="PART_DownButton"
|
103
|
+
Grid.Row="1"
|
104
|
+
Grid.Column="1"
|
105
|
+
HorizontalAlignment="Stretch"
|
106
|
+
Content="Down" />
|
107
|
+
</Grid>
|
108
|
+
</Border>
|
109
|
+
</ControlTemplate>
|
110
|
+
</Setter.Value>
|
111
|
+
</Setter>
|
112
|
+
</Style>
|
113
|
+
</ResourceDictionary>
|
114
|
+
```
|
115
|
+
|
116
|
+
```cs:NumericUpDown.cs
|
117
|
+
using Windows.UI.Xaml;
|
118
|
+
using Windows.UI.Xaml.Controls;
|
119
|
+
using Windows.UI.Xaml.Controls.Primitives;
|
120
|
+
|
121
|
+
|
122
|
+
namespace ClassLibrary1
|
123
|
+
{
|
124
|
+
public sealed class NumericUpDown : Control
|
125
|
+
{
|
126
|
+
public static readonly DependencyProperty ValueProperty
|
127
|
+
= DependencyProperty.Register(nameof(Value), typeof(int), typeof(NumericUpDown), new PropertyMetadata(0));
|
128
|
+
public int Value
|
129
|
+
{
|
130
|
+
get => (int)GetValue(ValueProperty);
|
131
|
+
set => SetValue(ValueProperty, value);
|
132
|
+
}
|
133
|
+
|
134
|
+
private RepeatButton upButton;
|
135
|
+
private RepeatButton downButton;
|
136
|
+
|
137
|
+
public NumericUpDown() => DefaultStyleKey = typeof(NumericUpDown);
|
138
|
+
|
139
|
+
|
140
|
+
private void UpClick(object sender, RoutedEventArgs e) => Value++;
|
141
|
+
private void DownClick(object sender, RoutedEventArgs e) => Value--;
|
142
|
+
|
143
|
+
protected override void OnApplyTemplate()
|
144
|
+
{
|
145
|
+
base.OnApplyTemplate();
|
146
|
+
|
147
|
+
if(upButton != null) upButton.Click -= UpClick;
|
148
|
+
if(downButton != null) downButton.Click -= DownClick;
|
149
|
+
|
150
|
+
upButton = GetTemplateChild("PART_UpButton") as RepeatButton;
|
151
|
+
downButton = GetTemplateChild("PART_DownButton") as RepeatButton;
|
152
|
+
|
153
|
+
if(upButton != null) upButton.Click += UpClick;
|
154
|
+
if(downButton != null) downButton.Click += DownClick;
|
155
|
+
}
|
156
|
+
}
|
157
|
+
}
|
158
|
+
```
|
159
|
+
他は初期状態
|
161
160
|

|
2
検証追記
answer
CHANGED
@@ -11,4 +11,151 @@
|
|
11
11
|
ちょっと例を書いてみようと思ったのですが、↑で十分でしょうか。
|
12
12
|
|
13
13
|
[C++/WinRT による XAML カスタム (テンプレート化) コントロール - UWP applications | Microsoft Docs](https://docs.microsoft.com/ja-jp/windows/uwp/cpp-and-winrt-apis/xaml-cust-ctrl)
|
14
|
-
公式での説明はC++での例しか見つけられませんでした。
|
14
|
+
公式での説明はC++での例しか見つけられませんでした。
|
15
|
+
|
16
|
+
---
|
17
|
+
|
18
|
+
> 見た目や処理が同じPageが多々でてきますので、
|
19
|
+
> なにかベースになるものを用意し、
|
20
|
+
> そこから派生して、
|
21
|
+
> オリジナルのコンポーネントを作成
|
22
|
+
|
23
|
+
には全く役に立ちませんが、テンプレート コントロールの検証です。
|
24
|
+
|
25
|
+
なんかネタが思いつかなかったので、またかずきさんのお借りしました^^;
|
26
|
+
[WPF4.5入門 その54 「カスタムコントロール」 - かずきのBlog@hatena](https://blog.okazuki.jp/entry/2014/09/08/221209)
|
27
|
+
|
28
|
+
|
29
|
+
App1プロジェクト MainPage.xaml
|
30
|
+
```xaml
|
31
|
+
<Page
|
32
|
+
x:Class="App1.MainPage"
|
33
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
34
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
35
|
+
xmlns:classLibrary1="using:ClassLibrary1"
|
36
|
+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
37
|
+
|
38
|
+
<StackPanel>
|
39
|
+
<classLibrary1:NumericUpDown
|
40
|
+
HorizontalAlignment="Left"
|
41
|
+
Background="LightBlue"
|
42
|
+
BorderBrush="Green"
|
43
|
+
BorderThickness="2"
|
44
|
+
FontSize="36"
|
45
|
+
Foreground="Red"
|
46
|
+
Value="100" />
|
47
|
+
|
48
|
+
<classLibrary1:NumericUpDown HorizontalAlignment="Left">
|
49
|
+
<classLibrary1:NumericUpDown.Template>
|
50
|
+
<ControlTemplate TargetType="classLibrary1:NumericUpDown">
|
51
|
+
<StackPanel>
|
52
|
+
<RepeatButton x:Name="PART_UpButton" HorizontalAlignment="Stretch">
|
53
|
+
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="" />
|
54
|
+
</RepeatButton>
|
55
|
+
<TextBlock HorizontalAlignment="Center" Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}}" />
|
56
|
+
<RepeatButton x:Name="PART_DownButton" HorizontalAlignment="Stretch">
|
57
|
+
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="" />
|
58
|
+
</RepeatButton>
|
59
|
+
</StackPanel>
|
60
|
+
</ControlTemplate>
|
61
|
+
</classLibrary1:NumericUpDown.Template>
|
62
|
+
</classLibrary1:NumericUpDown>
|
63
|
+
</StackPanel>
|
64
|
+
</Page>
|
65
|
+
```
|
66
|
+
|
67
|
+
ClassLibrary1プロジェクト Generic.xaml
|
68
|
+
```xaml
|
69
|
+
<ResourceDictionary
|
70
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
71
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
72
|
+
xmlns:local="using:ClassLibrary1">
|
73
|
+
<Style TargetType="local:NumericUpDown">
|
74
|
+
<Setter Property="Template">
|
75
|
+
<Setter.Value>
|
76
|
+
<ControlTemplate TargetType="local:NumericUpDown">
|
77
|
+
<Border
|
78
|
+
Background="{TemplateBinding Background}"
|
79
|
+
BorderBrush="{TemplateBinding BorderBrush}"
|
80
|
+
BorderThickness="{TemplateBinding BorderThickness}">
|
81
|
+
<Grid>
|
82
|
+
<Grid.RowDefinitions>
|
83
|
+
<RowDefinition />
|
84
|
+
<RowDefinition />
|
85
|
+
</Grid.RowDefinitions>
|
86
|
+
<Grid.ColumnDefinitions>
|
87
|
+
<ColumnDefinition />
|
88
|
+
<ColumnDefinition />
|
89
|
+
</Grid.ColumnDefinitions>
|
90
|
+
<TextBlock
|
91
|
+
Grid.RowSpan="2"
|
92
|
+
VerticalAlignment="Center"
|
93
|
+
Foreground="{TemplateBinding Foreground}"
|
94
|
+
Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}}"
|
95
|
+
TextWrapping="Wrap" />
|
96
|
+
<RepeatButton
|
97
|
+
x:Name="PART_UpButton"
|
98
|
+
Grid.Column="1"
|
99
|
+
HorizontalAlignment="Stretch"
|
100
|
+
Content="Up" />
|
101
|
+
<RepeatButton
|
102
|
+
x:Name="PART_DownButton"
|
103
|
+
Grid.Row="1"
|
104
|
+
Grid.Column="1"
|
105
|
+
HorizontalAlignment="Stretch"
|
106
|
+
Content="Down" />
|
107
|
+
</Grid>
|
108
|
+
</Border>
|
109
|
+
</ControlTemplate>
|
110
|
+
</Setter.Value>
|
111
|
+
</Setter>
|
112
|
+
</Style>
|
113
|
+
</ResourceDictionary>
|
114
|
+
```
|
115
|
+
|
116
|
+
ClassLibrary1プロジェクト NumericUpDown.cs
|
117
|
+
```C#
|
118
|
+
using Windows.UI.Xaml;
|
119
|
+
using Windows.UI.Xaml.Controls;
|
120
|
+
using Windows.UI.Xaml.Controls.Primitives;
|
121
|
+
|
122
|
+
|
123
|
+
namespace ClassLibrary1
|
124
|
+
{
|
125
|
+
public sealed class NumericUpDown : Control
|
126
|
+
{
|
127
|
+
public static readonly DependencyProperty ValueProperty
|
128
|
+
= DependencyProperty.Register(nameof(Value), typeof(int), typeof(NumericUpDown), new PropertyMetadata(0));
|
129
|
+
public int Value
|
130
|
+
{
|
131
|
+
get => (int)GetValue(ValueProperty);
|
132
|
+
set => SetValue(ValueProperty, value);
|
133
|
+
}
|
134
|
+
|
135
|
+
private RepeatButton upButton;
|
136
|
+
private RepeatButton downButton;
|
137
|
+
|
138
|
+
public NumericUpDown() => DefaultStyleKey = typeof(NumericUpDown);
|
139
|
+
|
140
|
+
|
141
|
+
private void UpClick(object sender, RoutedEventArgs e) => Value++;
|
142
|
+
private void DownClick(object sender, RoutedEventArgs e) => Value--;
|
143
|
+
|
144
|
+
protected override void OnApplyTemplate()
|
145
|
+
{
|
146
|
+
base.OnApplyTemplate();
|
147
|
+
|
148
|
+
if(upButton != null) upButton.Click -= UpClick;
|
149
|
+
if(downButton != null) downButton.Click -= DownClick;
|
150
|
+
|
151
|
+
upButton = GetTemplateChild("PART_UpButton") as RepeatButton;
|
152
|
+
downButton = GetTemplateChild("PART_DownButton") as RepeatButton;
|
153
|
+
|
154
|
+
if(upButton != null) upButton.Click += UpClick;
|
155
|
+
if(downButton != null) downButton.Click += DownClick;
|
156
|
+
}
|
157
|
+
}
|
158
|
+
}
|
159
|
+
```
|
160
|
+
他は初期状態
|
161
|
+

|
1
用語追記
answer
CHANGED
@@ -1,2 +1,14 @@
|
|
1
1
|
カスタムコントロールを作ってください。
|
2
|
-
`UWP`向けの記事があんまり見つからないので、`WPF`で調べてください(試してないですが流れは同じはずです^^;
|
2
|
+
`UWP`向けの記事があんまり見つからないので、`WPF`で調べてください(試してないですが流れは同じはずです^^;
|
3
|
+
|
4
|
+
---
|
5
|
+
|
6
|
+
`UWP`では「**テンプレート コントロール**」という用語になっているようです(コントロールテンプレートだとまた別の意味になってしまいます)
|
7
|
+

|
8
|
+
右の説明やファイル名はカスタムコントロールなのに。。。
|
9
|
+
|
10
|
+
[Windows ストア アプリでページ間で共通の見た目を簡単に作りたい - かずきのBlog@hatena](https://blog.okazuki.jp/entry/2014/01/09/003357)
|
11
|
+
ちょっと例を書いてみようと思ったのですが、↑で十分でしょうか。
|
12
|
+
|
13
|
+
[C++/WinRT による XAML カスタム (テンプレート化) コントロール - UWP applications | Microsoft Docs](https://docs.microsoft.com/ja-jp/windows/uwp/cpp-and-winrt-apis/xaml-cust-ctrl)
|
14
|
+
公式での説明はC++での例しか見つけられませんでした。
|