質問編集履歴
3
コードの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -50,16 +50,7 @@
|
|
50
50
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
51
51
|
xmlns:local="clr-namespace:MyWpf.Controls">
|
52
52
|
<Style TargetType="{x:Type local:CustomControl1}" BasedOn="{StaticResource {x:Type TextBox}}">
|
53
|
-
|
53
|
+
|
54
|
-
<Setter.Value>
|
55
|
-
<ControlTemplate TargetType="{x:Type local:CustomControl1}">
|
56
|
-
<Border Background="{TemplateBinding Background}"
|
57
|
-
BorderBrush="{TemplateBinding BorderBrush}"
|
58
|
-
BorderThickness="{TemplateBinding BorderThickness}">
|
59
|
-
</Border>
|
60
|
-
</ControlTemplate>
|
61
|
-
</Setter.Value>
|
62
|
-
</Setter>
|
63
54
|
</Style>
|
64
55
|
</ResourceDictionary>
|
65
56
|
```
|
2
コードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,9 +2,121 @@
|
|
2
2
|
|
3
3
|
#追記
|
4
4
|
言葉足らずで申し訳ありません。
|
5
|
-
MaterialDesignは「Material Design In XAML Toolkit」というライブラリを使用してコントロールのスタイルを変えたという意味で使いました。
|
5
|
+
MaterialDesignは「Material Design In XAML Toolkit」(Nugetでインストール)というライブラリを使用してコントロールのスタイルを変えたという意味で使いました。
|
6
6
|
|
7
7
|
導入後はButton、ListBox、TextBox等確かにデザインは反映されたのですが、カスタムコントロールだけが通常のスタイルのままです。
|
8
8
|
CSSでいうインラインスタイルでの指定ではなく、外部ファイル等でタグに直接スタイルを指定する・・・と言うような方法を探してします。
|
9
9
|
|
10
|
-
以上ご教示よろしくお願いいたします。
|
10
|
+
以上ご教示よろしくお願いいたします。
|
11
|
+
|
12
|
+
#追記2
|
13
|
+
Zuishinさんの示したコードでサンプルプロジェクトを作りやってみたところ適当に複数個配置したTextBoxにはスタイルが適用されましたが、サンプルプロジェクトではない今回のプロジェクトではMaterialDesignのスタイルは適用されませんでした。
|
14
|
+
|
15
|
+
App.xamlで上記でとった方法と同じような事をしていると思うのですが、配置したカスタムコントロール(TextBox)には適用されなかったです。
|
16
|
+
なんとなくZuishinさんの示したコードで全体に適用する原理はつかめたのですがなぜこれで適用されないのかが疑問です。
|
17
|
+
|
18
|
+
CustomControl1.cs
|
19
|
+
```C#
|
20
|
+
using System;
|
21
|
+
using System.Collections.Generic;
|
22
|
+
using System.Linq;
|
23
|
+
using System.Text;
|
24
|
+
using System.Threading.Tasks;
|
25
|
+
using System.Windows;
|
26
|
+
using System.Windows.Controls;
|
27
|
+
using System.Windows.Data;
|
28
|
+
using System.Windows.Documents;
|
29
|
+
using System.Windows.Input;
|
30
|
+
using System.Windows.Media;
|
31
|
+
using System.Windows.Media.Imaging;
|
32
|
+
using System.Windows.Navigation;
|
33
|
+
using System.Windows.Shapes;
|
34
|
+
|
35
|
+
namespace MyWpf.Controls
|
36
|
+
{
|
37
|
+
public class CustomControl1 : TextBox
|
38
|
+
{
|
39
|
+
static CustomControl1()
|
40
|
+
{
|
41
|
+
DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl1), new FrameworkPropertyMetadata(typeof(CustomControl1)));
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
```
|
46
|
+
Generic.xaml
|
47
|
+
```XAML
|
48
|
+
<ResourceDictionary
|
49
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
50
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
51
|
+
xmlns:local="clr-namespace:MyWpf.Controls">
|
52
|
+
<Style TargetType="{x:Type local:CustomControl1}" BasedOn="{StaticResource {x:Type TextBox}}">
|
53
|
+
<Setter Property="Template">
|
54
|
+
<Setter.Value>
|
55
|
+
<ControlTemplate TargetType="{x:Type local:CustomControl1}">
|
56
|
+
<Border Background="{TemplateBinding Background}"
|
57
|
+
BorderBrush="{TemplateBinding BorderBrush}"
|
58
|
+
BorderThickness="{TemplateBinding BorderThickness}">
|
59
|
+
</Border>
|
60
|
+
</ControlTemplate>
|
61
|
+
</Setter.Value>
|
62
|
+
</Setter>
|
63
|
+
</Style>
|
64
|
+
</ResourceDictionary>
|
65
|
+
```
|
66
|
+
MainWindow.xaml
|
67
|
+
```XAML
|
68
|
+
<Window
|
69
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
70
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
71
|
+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
72
|
+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
73
|
+
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
74
|
+
xmlns:local="clr-namespace:MaterialWindow"
|
75
|
+
xmlns:Controls="clr-namespace:MyWpf.Controls"
|
76
|
+
x:Class="MaterialWindow.MainWindow"
|
77
|
+
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
|
78
|
+
TextElement.FontWeight="Regular"
|
79
|
+
TextElement.FontSize="13"
|
80
|
+
TextOptions.TextFormattingMode="Ideal"
|
81
|
+
TextOptions.TextRenderingMode="Auto"
|
82
|
+
Background="{DynamicResource MaterialDesignPaper}"
|
83
|
+
FontFamily="{DynamicResource MaterialDesignFont}"
|
84
|
+
mc:Ignorable="d"
|
85
|
+
Title="MainWindow" Height="450" Width="800">
|
86
|
+
|
87
|
+
<Grid>
|
88
|
+
<Controls:CustomControl1 HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="CustomControl1 " VerticalAlignment="Top" Width="120"/>
|
89
|
+
</Grid>
|
90
|
+
</Window>
|
91
|
+
|
92
|
+
```
|
93
|
+
App.xaml
|
94
|
+
```XAML
|
95
|
+
<Application
|
96
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
97
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
98
|
+
xmlns:local="clr-namespace:MaterialWindow"
|
99
|
+
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" x:Class="MaterialWindow.App"
|
100
|
+
StartupUri="MainWindow.xaml">
|
101
|
+
<Application.Resources>
|
102
|
+
<ResourceDictionary>
|
103
|
+
<ResourceDictionary.MergedDictionaries>
|
104
|
+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml" />
|
105
|
+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
|
106
|
+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
|
107
|
+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
|
108
|
+
</ResourceDictionary.MergedDictionaries>
|
109
|
+
<!-- primary -->
|
110
|
+
<SolidColorBrush x:Key="PrimaryHueLightBrush" Color="#744CE0"/>
|
111
|
+
<SolidColorBrush x:Key="PrimaryHueLightForegroundBrush" Color="#FFFFFF"/>
|
112
|
+
<SolidColorBrush x:Key="PrimaryHueMidBrush" Color="#6134D9"/>
|
113
|
+
<SolidColorBrush x:Key="PrimaryHueMidForegroundBrush" Color="#FFFFFF"/>
|
114
|
+
<SolidColorBrush x:Key="PrimaryHueDarkBrush" Color="#4D1DCF"/>
|
115
|
+
<SolidColorBrush x:Key="PrimaryHueDarkForegroundBrush" Color="#FFFFFF"/>
|
116
|
+
<!-- accent -->
|
117
|
+
<SolidColorBrush x:Key="SecondaryAccentBrush" Color="#5C5B5E"/>
|
118
|
+
<SolidColorBrush x:Key="SecondaryAccentForegroundBrush" Color="#FFFFFF"/>
|
119
|
+
</ResourceDictionary>
|
120
|
+
</Application.Resources>
|
121
|
+
</Application>
|
122
|
+
```
|
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
-
XAMLから直接「Style="{StaticResource MaterialDesignTextBox}」と指定すると反映されますが、そうではなくデフォルトで反映させたいのですがどのようにしたらよいでしょうか?
|
1
|
+
カスタム化したTextBoxExにXAMLから直接「Style="{StaticResource MaterialDesignTextBox}」と指定すると反映されますが、そうではなくデフォルトで反映させたいのですがどのようにしたらよいでしょうか?
|
2
2
|
|
3
|
+
#追記
|
4
|
+
言葉足らずで申し訳ありません。
|
5
|
+
MaterialDesignは「Material Design In XAML Toolkit」というライブラリを使用してコントロールのスタイルを変えたという意味で使いました。
|
6
|
+
|
7
|
+
導入後はButton、ListBox、TextBox等確かにデザインは反映されたのですが、カスタムコントロールだけが通常のスタイルのままです。
|
8
|
+
CSSでいうインラインスタイルでの指定ではなく、外部ファイル等でタグに直接スタイルを指定する・・・と言うような方法を探してします。
|
9
|
+
|
3
10
|
以上ご教示よろしくお願いいたします。
|