質問編集履歴
3
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -102,25 +102,7 @@
|
|
102
102
|
|
103
103
|
<Style TargetType="{x:Type local:CustomControl1}" BasedOn="{StaticResource {x:Type TextBox}}">
|
104
104
|
|
105
|
-
|
105
|
+
|
106
|
-
|
107
|
-
<Setter.Value>
|
108
|
-
|
109
|
-
<ControlTemplate TargetType="{x:Type local:CustomControl1}">
|
110
|
-
|
111
|
-
<Border Background="{TemplateBinding Background}"
|
112
|
-
|
113
|
-
BorderBrush="{TemplateBinding BorderBrush}"
|
114
|
-
|
115
|
-
BorderThickness="{TemplateBinding BorderThickness}">
|
116
|
-
|
117
|
-
</Border>
|
118
|
-
|
119
|
-
</ControlTemplate>
|
120
|
-
|
121
|
-
</Setter.Value>
|
122
|
-
|
123
|
-
</Setter>
|
124
106
|
|
125
107
|
</Style>
|
126
108
|
|
2
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
言葉足らずで申し訳ありません。
|
8
8
|
|
9
|
-
MaterialDesignは「Material Design In XAML Toolkit」というライブラリを使用してコントロールのスタイルを変えたという意味で使いました。
|
9
|
+
MaterialDesignは「Material Design In XAML Toolkit」(Nugetでインストール)というライブラリを使用してコントロールのスタイルを変えたという意味で使いました。
|
10
10
|
|
11
11
|
|
12
12
|
|
@@ -17,3 +17,227 @@
|
|
17
17
|
|
18
18
|
|
19
19
|
以上ご教示よろしくお願いいたします。
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
#追記2
|
24
|
+
|
25
|
+
Zuishinさんの示したコードでサンプルプロジェクトを作りやってみたところ適当に複数個配置したTextBoxにはスタイルが適用されましたが、サンプルプロジェクトではない今回のプロジェクトではMaterialDesignのスタイルは適用されませんでした。
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
App.xamlで上記でとった方法と同じような事をしていると思うのですが、配置したカスタムコントロール(TextBox)には適用されなかったです。
|
30
|
+
|
31
|
+
なんとなくZuishinさんの示したコードで全体に適用する原理はつかめたのですがなぜこれで適用されないのかが疑問です。
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
CustomControl1.cs
|
36
|
+
|
37
|
+
```C#
|
38
|
+
|
39
|
+
using System;
|
40
|
+
|
41
|
+
using System.Collections.Generic;
|
42
|
+
|
43
|
+
using System.Linq;
|
44
|
+
|
45
|
+
using System.Text;
|
46
|
+
|
47
|
+
using System.Threading.Tasks;
|
48
|
+
|
49
|
+
using System.Windows;
|
50
|
+
|
51
|
+
using System.Windows.Controls;
|
52
|
+
|
53
|
+
using System.Windows.Data;
|
54
|
+
|
55
|
+
using System.Windows.Documents;
|
56
|
+
|
57
|
+
using System.Windows.Input;
|
58
|
+
|
59
|
+
using System.Windows.Media;
|
60
|
+
|
61
|
+
using System.Windows.Media.Imaging;
|
62
|
+
|
63
|
+
using System.Windows.Navigation;
|
64
|
+
|
65
|
+
using System.Windows.Shapes;
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
namespace MyWpf.Controls
|
70
|
+
|
71
|
+
{
|
72
|
+
|
73
|
+
public class CustomControl1 : TextBox
|
74
|
+
|
75
|
+
{
|
76
|
+
|
77
|
+
static CustomControl1()
|
78
|
+
|
79
|
+
{
|
80
|
+
|
81
|
+
DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl1), new FrameworkPropertyMetadata(typeof(CustomControl1)));
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
```
|
90
|
+
|
91
|
+
Generic.xaml
|
92
|
+
|
93
|
+
```XAML
|
94
|
+
|
95
|
+
<ResourceDictionary
|
96
|
+
|
97
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
98
|
+
|
99
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
100
|
+
|
101
|
+
xmlns:local="clr-namespace:MyWpf.Controls">
|
102
|
+
|
103
|
+
<Style TargetType="{x:Type local:CustomControl1}" BasedOn="{StaticResource {x:Type TextBox}}">
|
104
|
+
|
105
|
+
<Setter Property="Template">
|
106
|
+
|
107
|
+
<Setter.Value>
|
108
|
+
|
109
|
+
<ControlTemplate TargetType="{x:Type local:CustomControl1}">
|
110
|
+
|
111
|
+
<Border Background="{TemplateBinding Background}"
|
112
|
+
|
113
|
+
BorderBrush="{TemplateBinding BorderBrush}"
|
114
|
+
|
115
|
+
BorderThickness="{TemplateBinding BorderThickness}">
|
116
|
+
|
117
|
+
</Border>
|
118
|
+
|
119
|
+
</ControlTemplate>
|
120
|
+
|
121
|
+
</Setter.Value>
|
122
|
+
|
123
|
+
</Setter>
|
124
|
+
|
125
|
+
</Style>
|
126
|
+
|
127
|
+
</ResourceDictionary>
|
128
|
+
|
129
|
+
```
|
130
|
+
|
131
|
+
MainWindow.xaml
|
132
|
+
|
133
|
+
```XAML
|
134
|
+
|
135
|
+
<Window
|
136
|
+
|
137
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
138
|
+
|
139
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
140
|
+
|
141
|
+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
142
|
+
|
143
|
+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
144
|
+
|
145
|
+
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
146
|
+
|
147
|
+
xmlns:local="clr-namespace:MaterialWindow"
|
148
|
+
|
149
|
+
xmlns:Controls="clr-namespace:MyWpf.Controls"
|
150
|
+
|
151
|
+
x:Class="MaterialWindow.MainWindow"
|
152
|
+
|
153
|
+
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
|
154
|
+
|
155
|
+
TextElement.FontWeight="Regular"
|
156
|
+
|
157
|
+
TextElement.FontSize="13"
|
158
|
+
|
159
|
+
TextOptions.TextFormattingMode="Ideal"
|
160
|
+
|
161
|
+
TextOptions.TextRenderingMode="Auto"
|
162
|
+
|
163
|
+
Background="{DynamicResource MaterialDesignPaper}"
|
164
|
+
|
165
|
+
FontFamily="{DynamicResource MaterialDesignFont}"
|
166
|
+
|
167
|
+
mc:Ignorable="d"
|
168
|
+
|
169
|
+
Title="MainWindow" Height="450" Width="800">
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
<Grid>
|
174
|
+
|
175
|
+
<Controls:CustomControl1 HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="CustomControl1 " VerticalAlignment="Top" Width="120"/>
|
176
|
+
|
177
|
+
</Grid>
|
178
|
+
|
179
|
+
</Window>
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
```
|
184
|
+
|
185
|
+
App.xaml
|
186
|
+
|
187
|
+
```XAML
|
188
|
+
|
189
|
+
<Application
|
190
|
+
|
191
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
192
|
+
|
193
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
194
|
+
|
195
|
+
xmlns:local="clr-namespace:MaterialWindow"
|
196
|
+
|
197
|
+
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" x:Class="MaterialWindow.App"
|
198
|
+
|
199
|
+
StartupUri="MainWindow.xaml">
|
200
|
+
|
201
|
+
<Application.Resources>
|
202
|
+
|
203
|
+
<ResourceDictionary>
|
204
|
+
|
205
|
+
<ResourceDictionary.MergedDictionaries>
|
206
|
+
|
207
|
+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml" />
|
208
|
+
|
209
|
+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
|
210
|
+
|
211
|
+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
|
212
|
+
|
213
|
+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
|
214
|
+
|
215
|
+
</ResourceDictionary.MergedDictionaries>
|
216
|
+
|
217
|
+
<!-- primary -->
|
218
|
+
|
219
|
+
<SolidColorBrush x:Key="PrimaryHueLightBrush" Color="#744CE0"/>
|
220
|
+
|
221
|
+
<SolidColorBrush x:Key="PrimaryHueLightForegroundBrush" Color="#FFFFFF"/>
|
222
|
+
|
223
|
+
<SolidColorBrush x:Key="PrimaryHueMidBrush" Color="#6134D9"/>
|
224
|
+
|
225
|
+
<SolidColorBrush x:Key="PrimaryHueMidForegroundBrush" Color="#FFFFFF"/>
|
226
|
+
|
227
|
+
<SolidColorBrush x:Key="PrimaryHueDarkBrush" Color="#4D1DCF"/>
|
228
|
+
|
229
|
+
<SolidColorBrush x:Key="PrimaryHueDarkForegroundBrush" Color="#FFFFFF"/>
|
230
|
+
|
231
|
+
<!-- accent -->
|
232
|
+
|
233
|
+
<SolidColorBrush x:Key="SecondaryAccentBrush" Color="#5C5B5E"/>
|
234
|
+
|
235
|
+
<SolidColorBrush x:Key="SecondaryAccentForegroundBrush" Color="#FFFFFF"/>
|
236
|
+
|
237
|
+
</ResourceDictionary>
|
238
|
+
|
239
|
+
</Application.Resources>
|
240
|
+
|
241
|
+
</Application>
|
242
|
+
|
243
|
+
```
|
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,18 @@
|
|
1
|
-
XAMLから直接「Style="{StaticResource MaterialDesignTextBox}」と指定すると反映されますが、そうではなくデフォルトで反映させたいのですがどのようにしたらよいでしょうか?
|
1
|
+
カスタム化したTextBoxExにXAMLから直接「Style="{StaticResource MaterialDesignTextBox}」と指定すると反映されますが、そうではなくデフォルトで反映させたいのですがどのようにしたらよいでしょうか?
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
#追記
|
6
|
+
|
7
|
+
言葉足らずで申し訳ありません。
|
8
|
+
|
9
|
+
MaterialDesignは「Material Design In XAML Toolkit」というライブラリを使用してコントロールのスタイルを変えたという意味で使いました。
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
導入後はButton、ListBox、TextBox等確かにデザインは反映されたのですが、カスタムコントロールだけが通常のスタイルのままです。
|
14
|
+
|
15
|
+
CSSでいうインラインスタイルでの指定ではなく、外部ファイル等でタグに直接スタイルを指定する・・・と言うような方法を探してします。
|
2
16
|
|
3
17
|
|
4
18
|
|