回答編集履歴
1
見直しキャンペーン中
answer
CHANGED
@@ -1,160 +1,160 @@
|
|
1
|
-
> 最悪、ControlTemplate自体をコピーして、該当部分を書き換える?と思うのですが、もっとスマートな方法がある気がしてなりません。
|
2
|
-
|
3
|
-
`Style`で`BasedOn`するような手軽な方法は、`Template`では残念ながら無いです。
|
4
|
-
|
5
|
-
今回の例ですと`ItemContainerStyle`の`Template`で、`MaterialDesignComboBoxItemTemplate`をほぼコピペすることになります。
|
6
|
-
|
7
|
-
```
|
8
|
-
<Window
|
9
|
-
x:Class="Questions302763.MainWindow"
|
10
|
-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
11
|
-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
12
|
-
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
13
|
-
Width="800"
|
14
|
-
Height="450">
|
15
|
-
<Window.Resources>
|
16
|
-
<Style BasedOn="{StaticResource MaterialDesignComboBox}" TargetType="{x:Type ComboBox}">
|
17
|
-
<Setter Property="ItemContainerStyle">
|
18
|
-
<Setter.Value>
|
19
|
-
<Style BasedOn="{StaticResource MaterialDesignComboBoxItemSelectedCollapsedStyle}" TargetType="{x:Type ComboBoxItem}">
|
20
|
-
<Setter Property="Template">
|
21
|
-
<Setter.Value>
|
22
|
-
<ControlTemplate TargetType="{x:Type ComboBoxItem}">
|
23
|
-
<Grid x:Name="GridWrapper">
|
24
|
-
<Grid.RowDefinitions>
|
25
|
-
<RowDefinition Height="Auto" />
|
26
|
-
</Grid.RowDefinitions>
|
27
|
-
|
28
|
-
<Border
|
29
|
-
x:Name="BackBorder"
|
30
|
-
Background="{TemplateBinding Background}"
|
31
|
-
BorderBrush="{TemplateBinding BorderBrush}"
|
32
|
-
BorderThickness="{TemplateBinding BorderThickness}"
|
33
|
-
SnapsToDevicePixels="True" />
|
34
|
-
|
35
|
-
<Border
|
36
|
-
x:Name="MouseOverBorder"
|
37
|
-
Background="{TemplateBinding Foreground,
|
38
|
-
Converter={StaticResource BrushRoundConverter}}"
|
39
|
-
BorderBrush="{TemplateBinding BorderBrush}"
|
40
|
-
BorderThickness="{TemplateBinding BorderThickness}"
|
41
|
-
Opacity="0"
|
42
|
-
SnapsToDevicePixels="True" />
|
43
|
-
<Border
|
44
|
-
x:Name="SelectedBorder"
|
45
|
-
Background="{TemplateBinding Foreground,
|
46
|
-
Converter={StaticResource BrushRoundConverter}}"
|
47
|
-
Opacity="0"
|
48
|
-
RenderTransformOrigin="0.5,0.5" />
|
49
|
-
<materialDesign:Ripple
|
50
|
-
Padding="{TemplateBinding Padding}"
|
51
|
-
HorizontalAlignment="Stretch"
|
52
|
-
VerticalAlignment="Stretch"
|
53
|
-
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
54
|
-
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
55
|
-
Content="{TemplateBinding Content}"
|
56
|
-
ContentTemplate="{TemplateBinding ContentTemplate}"
|
57
|
-
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
|
58
|
-
Feedback="{TemplateBinding Foreground,
|
59
|
-
Converter={StaticResource BrushRoundConverter}}"
|
60
|
-
Focusable="False"
|
61
|
-
RecognizesAccessKey="False"
|
62
|
-
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
|
63
|
-
<VisualStateManager.VisualStateGroups>
|
64
|
-
<VisualStateGroup Name="CommonStates">
|
65
|
-
<VisualStateGroup.Transitions>
|
66
|
-
<VisualTransition GeneratedDuration="0:0:0.1" To="Normal">
|
67
|
-
<VisualTransition.GeneratedEasingFunction>
|
68
|
-
<CircleEase EasingMode="EaseOut" />
|
69
|
-
</VisualTransition.GeneratedEasingFunction>
|
70
|
-
</VisualTransition>
|
71
|
-
</VisualStateGroup.Transitions>
|
72
|
-
<VisualState Name="Normal" />
|
73
|
-
<VisualState Name="MouseOver">
|
74
|
-
<Storyboard>
|
75
|
-
<DoubleAnimation
|
76
|
-
Storyboard.TargetName="MouseOverBorder"
|
77
|
-
Storyboard.TargetProperty="Opacity"
|
78
|
-
To="0.1"
|
79
|
-
Duration="0" />
|
80
|
-
</Storyboard>
|
81
|
-
</VisualState>
|
82
|
-
</VisualStateGroup>
|
83
|
-
<VisualStateGroup Name="SelectionStates">
|
84
|
-
<VisualStateGroup.Transitions>
|
85
|
-
<VisualTransition GeneratedDuration="0:0:0.1" />
|
86
|
-
</VisualStateGroup.Transitions>
|
87
|
-
<VisualState Name="Selected">
|
88
|
-
<Storyboard>
|
89
|
-
<DoubleAnimation
|
90
|
-
Storyboard.TargetName="SelectedBorder"
|
91
|
-
Storyboard.TargetProperty="Opacity"
|
92
|
-
To="0.18"
|
93
|
-
Duration="0" />
|
94
|
-
</Storyboard>
|
95
|
-
</VisualState>
|
96
|
-
<VisualState Name="Unselected" />
|
97
|
-
</VisualStateGroup>
|
98
|
-
<VisualStateGroup Name="FocusStates">
|
99
|
-
<VisualStateGroup.Transitions>
|
100
|
-
<VisualTransition GeneratedDuration="0:0:0.1" To="Unfocused" />
|
101
|
-
</VisualStateGroup.Transitions>
|
102
|
-
<VisualState Name="Focused">
|
103
|
-
<Storyboard>
|
104
|
-
<DoubleAnimation
|
105
|
-
Storyboard.TargetName="MouseOverBorder"
|
106
|
-
Storyboard.TargetProperty="Opacity"
|
107
|
-
To="0.1"
|
108
|
-
Duration="0" />
|
109
|
-
</Storyboard>
|
110
|
-
</VisualState>
|
111
|
-
<VisualState Name="Unfocused" />
|
112
|
-
</VisualStateGroup>
|
113
|
-
</VisualStateManager.VisualStateGroups>
|
114
|
-
</Grid>
|
115
|
-
<ControlTemplate.Triggers>
|
116
|
-
<Trigger Property="IsEnabled" Value="False">
|
117
|
-
<Setter TargetName="GridWrapper" Property="Opacity" Value="0.56" />
|
118
|
-
</Trigger>
|
119
|
-
<MultiTrigger>
|
120
|
-
<MultiTrigger.Conditions>
|
121
|
-
<Condition Property="Tag" Value="{StaticResource AllowCollapse}" />
|
122
|
-
<Condition Property="IsSelected" Value="True" />
|
123
|
-
</MultiTrigger.Conditions>
|
124
|
-
<Setter Property="Height" Value="0" />
|
125
|
-
</MultiTrigger>
|
126
|
-
</ControlTemplate.Triggers>
|
127
|
-
</ControlTemplate>
|
128
|
-
</Setter.Value>
|
129
|
-
</Setter>
|
130
|
-
</Style>
|
131
|
-
</Setter.Value>
|
132
|
-
</Setter>
|
133
|
-
</Style>
|
134
|
-
</Window.Resources>
|
135
|
-
<Grid>
|
136
|
-
<StackPanel>
|
137
|
-
<GroupBox Header="ノーマル">
|
138
|
-
<ComboBox Style="{StaticResource MaterialDesignComboBox}">
|
139
|
-
<ComboBoxItem>aaa</ComboBoxItem>
|
140
|
-
<ComboBoxItem>bbb</ComboBoxItem>
|
141
|
-
<ComboBoxItem>ccc</ComboBoxItem>
|
142
|
-
</ComboBox>
|
143
|
-
</GroupBox>
|
144
|
-
|
145
|
-
<GroupBox Header="キビキビ">
|
146
|
-
<ComboBox>
|
147
|
-
<ComboBoxItem>aaa</ComboBoxItem>
|
148
|
-
<ComboBoxItem>bbb</ComboBoxItem>
|
149
|
-
<ComboBoxItem>ccc</ComboBoxItem>
|
150
|
-
</ComboBox>
|
151
|
-
</GroupBox>
|
152
|
-
</StackPanel>
|
153
|
-
</Grid>
|
154
|
-
</Window>
|
155
|
-
```
|
156
|
-
|
157
|
-
---
|
158
|
-
|
159
|
-
s.promptさんとまったく同じことを思っている方はいるようですが、クローズしています(前向きに検討中なのか・やる気はないのかは、自動翻訳では読み取れなかったです^^;
|
1
|
+
> 最悪、ControlTemplate自体をコピーして、該当部分を書き換える?と思うのですが、もっとスマートな方法がある気がしてなりません。
|
2
|
+
|
3
|
+
`Style`で`BasedOn`するような手軽な方法は、`Template`では残念ながら無いです。
|
4
|
+
|
5
|
+
今回の例ですと`ItemContainerStyle`の`Template`で、`MaterialDesignComboBoxItemTemplate`をほぼコピペすることになります。
|
6
|
+
|
7
|
+
```xml
|
8
|
+
<Window
|
9
|
+
x:Class="Questions302763.MainWindow"
|
10
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
11
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
12
|
+
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
13
|
+
Width="800"
|
14
|
+
Height="450">
|
15
|
+
<Window.Resources>
|
16
|
+
<Style BasedOn="{StaticResource MaterialDesignComboBox}" TargetType="{x:Type ComboBox}">
|
17
|
+
<Setter Property="ItemContainerStyle">
|
18
|
+
<Setter.Value>
|
19
|
+
<Style BasedOn="{StaticResource MaterialDesignComboBoxItemSelectedCollapsedStyle}" TargetType="{x:Type ComboBoxItem}">
|
20
|
+
<Setter Property="Template">
|
21
|
+
<Setter.Value>
|
22
|
+
<ControlTemplate TargetType="{x:Type ComboBoxItem}">
|
23
|
+
<Grid x:Name="GridWrapper">
|
24
|
+
<Grid.RowDefinitions>
|
25
|
+
<RowDefinition Height="Auto" />
|
26
|
+
</Grid.RowDefinitions>
|
27
|
+
|
28
|
+
<Border
|
29
|
+
x:Name="BackBorder"
|
30
|
+
Background="{TemplateBinding Background}"
|
31
|
+
BorderBrush="{TemplateBinding BorderBrush}"
|
32
|
+
BorderThickness="{TemplateBinding BorderThickness}"
|
33
|
+
SnapsToDevicePixels="True" />
|
34
|
+
|
35
|
+
<Border
|
36
|
+
x:Name="MouseOverBorder"
|
37
|
+
Background="{TemplateBinding Foreground,
|
38
|
+
Converter={StaticResource BrushRoundConverter}}"
|
39
|
+
BorderBrush="{TemplateBinding BorderBrush}"
|
40
|
+
BorderThickness="{TemplateBinding BorderThickness}"
|
41
|
+
Opacity="0"
|
42
|
+
SnapsToDevicePixels="True" />
|
43
|
+
<Border
|
44
|
+
x:Name="SelectedBorder"
|
45
|
+
Background="{TemplateBinding Foreground,
|
46
|
+
Converter={StaticResource BrushRoundConverter}}"
|
47
|
+
Opacity="0"
|
48
|
+
RenderTransformOrigin="0.5,0.5" />
|
49
|
+
<materialDesign:Ripple
|
50
|
+
Padding="{TemplateBinding Padding}"
|
51
|
+
HorizontalAlignment="Stretch"
|
52
|
+
VerticalAlignment="Stretch"
|
53
|
+
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
54
|
+
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
55
|
+
Content="{TemplateBinding Content}"
|
56
|
+
ContentTemplate="{TemplateBinding ContentTemplate}"
|
57
|
+
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
|
58
|
+
Feedback="{TemplateBinding Foreground,
|
59
|
+
Converter={StaticResource BrushRoundConverter}}"
|
60
|
+
Focusable="False"
|
61
|
+
RecognizesAccessKey="False"
|
62
|
+
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
|
63
|
+
<VisualStateManager.VisualStateGroups>
|
64
|
+
<VisualStateGroup Name="CommonStates">
|
65
|
+
<VisualStateGroup.Transitions>
|
66
|
+
<VisualTransition GeneratedDuration="0:0:0.1" To="Normal">
|
67
|
+
<VisualTransition.GeneratedEasingFunction>
|
68
|
+
<CircleEase EasingMode="EaseOut" />
|
69
|
+
</VisualTransition.GeneratedEasingFunction>
|
70
|
+
</VisualTransition>
|
71
|
+
</VisualStateGroup.Transitions>
|
72
|
+
<VisualState Name="Normal" />
|
73
|
+
<VisualState Name="MouseOver">
|
74
|
+
<Storyboard>
|
75
|
+
<DoubleAnimation
|
76
|
+
Storyboard.TargetName="MouseOverBorder"
|
77
|
+
Storyboard.TargetProperty="Opacity"
|
78
|
+
To="0.1"
|
79
|
+
Duration="0" />
|
80
|
+
</Storyboard>
|
81
|
+
</VisualState>
|
82
|
+
</VisualStateGroup>
|
83
|
+
<VisualStateGroup Name="SelectionStates">
|
84
|
+
<VisualStateGroup.Transitions>
|
85
|
+
<VisualTransition GeneratedDuration="0:0:0.1" />
|
86
|
+
</VisualStateGroup.Transitions>
|
87
|
+
<VisualState Name="Selected">
|
88
|
+
<Storyboard>
|
89
|
+
<DoubleAnimation
|
90
|
+
Storyboard.TargetName="SelectedBorder"
|
91
|
+
Storyboard.TargetProperty="Opacity"
|
92
|
+
To="0.18"
|
93
|
+
Duration="0" />
|
94
|
+
</Storyboard>
|
95
|
+
</VisualState>
|
96
|
+
<VisualState Name="Unselected" />
|
97
|
+
</VisualStateGroup>
|
98
|
+
<VisualStateGroup Name="FocusStates">
|
99
|
+
<VisualStateGroup.Transitions>
|
100
|
+
<VisualTransition GeneratedDuration="0:0:0.1" To="Unfocused" />
|
101
|
+
</VisualStateGroup.Transitions>
|
102
|
+
<VisualState Name="Focused">
|
103
|
+
<Storyboard>
|
104
|
+
<DoubleAnimation
|
105
|
+
Storyboard.TargetName="MouseOverBorder"
|
106
|
+
Storyboard.TargetProperty="Opacity"
|
107
|
+
To="0.1"
|
108
|
+
Duration="0" />
|
109
|
+
</Storyboard>
|
110
|
+
</VisualState>
|
111
|
+
<VisualState Name="Unfocused" />
|
112
|
+
</VisualStateGroup>
|
113
|
+
</VisualStateManager.VisualStateGroups>
|
114
|
+
</Grid>
|
115
|
+
<ControlTemplate.Triggers>
|
116
|
+
<Trigger Property="IsEnabled" Value="False">
|
117
|
+
<Setter TargetName="GridWrapper" Property="Opacity" Value="0.56" />
|
118
|
+
</Trigger>
|
119
|
+
<MultiTrigger>
|
120
|
+
<MultiTrigger.Conditions>
|
121
|
+
<Condition Property="Tag" Value="{StaticResource AllowCollapse}" />
|
122
|
+
<Condition Property="IsSelected" Value="True" />
|
123
|
+
</MultiTrigger.Conditions>
|
124
|
+
<Setter Property="Height" Value="0" />
|
125
|
+
</MultiTrigger>
|
126
|
+
</ControlTemplate.Triggers>
|
127
|
+
</ControlTemplate>
|
128
|
+
</Setter.Value>
|
129
|
+
</Setter>
|
130
|
+
</Style>
|
131
|
+
</Setter.Value>
|
132
|
+
</Setter>
|
133
|
+
</Style>
|
134
|
+
</Window.Resources>
|
135
|
+
<Grid>
|
136
|
+
<StackPanel>
|
137
|
+
<GroupBox Header="ノーマル">
|
138
|
+
<ComboBox Style="{StaticResource MaterialDesignComboBox}">
|
139
|
+
<ComboBoxItem>aaa</ComboBoxItem>
|
140
|
+
<ComboBoxItem>bbb</ComboBoxItem>
|
141
|
+
<ComboBoxItem>ccc</ComboBoxItem>
|
142
|
+
</ComboBox>
|
143
|
+
</GroupBox>
|
144
|
+
|
145
|
+
<GroupBox Header="キビキビ">
|
146
|
+
<ComboBox>
|
147
|
+
<ComboBoxItem>aaa</ComboBoxItem>
|
148
|
+
<ComboBoxItem>bbb</ComboBoxItem>
|
149
|
+
<ComboBoxItem>ccc</ComboBoxItem>
|
150
|
+
</ComboBox>
|
151
|
+
</GroupBox>
|
152
|
+
</StackPanel>
|
153
|
+
</Grid>
|
154
|
+
</Window>
|
155
|
+
```
|
156
|
+
|
157
|
+
---
|
158
|
+
|
159
|
+
s.promptさんとまったく同じことを思っている方はいるようですが、クローズしています(前向きに検討中なのか・やる気はないのかは、自動翻訳では読み取れなかったです^^;
|
160
160
|
[Adding support for customization of visualtransition duration of combobox item to normal state by koutinho · Pull Request #1290 · MaterialDesignInXAML/MaterialDesignInXamlToolkit](https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/pull/1290)
|