回答編集履歴
1
見直しキャンペーン中
answer
CHANGED
@@ -1,106 +1,106 @@
|
|
1
|
-
> ボタンを横に並べ、
|
2
|
-
> トグルボタンのように動作させたいと思っている。
|
3
|
-
> できたら、どのボタンを押した状態なのかも把握したい。
|
4
|
-
|
5
|
-
Zuishinさんが書いておられますが、トグルボタンは既にあります。
|
6
|
-
[ToggleButton クラス (System.Windows.Controls.Primitives) | Microsoft Docs](https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.controls.primitives.togglebutton)
|
7
|
-
|
8
|
-
わかっておられるでしょうが、これは`CheckBox`のボタン版です。
|
9
|
-
それぞれにOn・Off状態があります。
|
10
|
-
|
11
|
-
そうではなく`RadioButton`のボタン版が欲しい場合は、スタイルを`ToggleButton`にするという大技?があります。
|
12
|
-
|
13
|
-
どちらもボタンの見た目な場合は、`ThreeState`は設定しないほうがいいでしょう。
|
14
|
-
まったく違いが判りません(自分でスタイルをいじる場合はその限りではありません)
|
15
|
-
|
16
|
-
|
17
|
-
> ボタンをクリックした場合、BackGroundまたはBorderを黄色にする
|
18
|
-
> クリックされなかったボタンはデフォルト色にする
|
19
|
-
|
20
|
-
スタイルをいじればどうとでもなりますが、何か理想の見た目がありますか?
|
21
|
-
|
22
|
-
```
|
23
|
-
<Window
|
24
|
-
x:Class="Questions353667.MainWindow"
|
25
|
-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
26
|
-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
27
|
-
SizeToContent="WidthAndHeight">
|
28
|
-
<StackPanel>
|
29
|
-
<GroupBox Header="CheckBox">
|
30
|
-
<StackPanel Orientation="Horizontal">
|
31
|
-
<CheckBox
|
32
|
-
MinWidth="50"
|
33
|
-
Content="C1"
|
34
|
-
IsChecked="True" />
|
35
|
-
<CheckBox
|
36
|
-
MinWidth="50"
|
37
|
-
Content="C2"
|
38
|
-
IsChecked="True" />
|
39
|
-
<CheckBox MinWidth="50" Content="C3" />
|
40
|
-
<CheckBox
|
41
|
-
MinWidth="50"
|
42
|
-
Content="C4"
|
43
|
-
IsChecked="{x:Null}"
|
44
|
-
IsThreeState="True" />
|
45
|
-
</StackPanel>
|
46
|
-
</GroupBox>
|
47
|
-
<GroupBox Header="ToggleButton">
|
48
|
-
<StackPanel Orientation="Horizontal">
|
49
|
-
<ToggleButton
|
50
|
-
MinWidth="50"
|
51
|
-
Content="B1"
|
52
|
-
IsChecked="True" />
|
53
|
-
<ToggleButton
|
54
|
-
MinWidth="50"
|
55
|
-
Content="B2"
|
56
|
-
IsChecked="True" />
|
57
|
-
<ToggleButton MinWidth="50" Content="B3" />
|
58
|
-
<ToggleButton
|
59
|
-
MinWidth="50"
|
60
|
-
Content="B4"
|
61
|
-
IsChecked="{x:Null}"
|
62
|
-
IsThreeState="True" />
|
63
|
-
</StackPanel>
|
64
|
-
</GroupBox>
|
65
|
-
<GroupBox Header="RadioButton">
|
66
|
-
<StackPanel Orientation="Horizontal">
|
67
|
-
<RadioButton
|
68
|
-
MinWidth="50"
|
69
|
-
Content="R1"
|
70
|
-
IsChecked="True" />
|
71
|
-
<RadioButton MinWidth="50" Content="R2" />
|
72
|
-
<RadioButton MinWidth="50" Content="R3" />
|
73
|
-
<RadioButton
|
74
|
-
MinWidth="50"
|
75
|
-
Content="R4"
|
76
|
-
IsChecked="{x:Null}"
|
77
|
-
IsThreeState="True" />
|
78
|
-
</StackPanel>
|
79
|
-
</GroupBox>
|
80
|
-
<GroupBox Header="RadioButton(Button Style)">
|
81
|
-
<StackPanel Orientation="Horizontal">
|
82
|
-
<RadioButton
|
83
|
-
MinWidth="50"
|
84
|
-
Content="B1"
|
85
|
-
IsChecked="True"
|
86
|
-
Style="{StaticResource {x:Type ToggleButton}}" />
|
87
|
-
<RadioButton
|
88
|
-
MinWidth="50"
|
89
|
-
Content="B2"
|
90
|
-
Style="{StaticResource {x:Type ToggleButton}}" />
|
91
|
-
<RadioButton
|
92
|
-
MinWidth="50"
|
93
|
-
Content="B3"
|
94
|
-
Style="{StaticResource {x:Type ToggleButton}}" />
|
95
|
-
<RadioButton
|
96
|
-
MinWidth="50"
|
97
|
-
Content="B4"
|
98
|
-
IsChecked="{x:Null}"
|
99
|
-
IsThreeState="True"
|
100
|
-
Style="{StaticResource {x:Type ToggleButton}}" />
|
101
|
-
</StackPanel>
|
102
|
-
</GroupBox>
|
103
|
-
</StackPanel>
|
104
|
-
</Window>
|
105
|
-
```
|
1
|
+
> ボタンを横に並べ、
|
2
|
+
> トグルボタンのように動作させたいと思っている。
|
3
|
+
> できたら、どのボタンを押した状態なのかも把握したい。
|
4
|
+
|
5
|
+
Zuishinさんが書いておられますが、トグルボタンは既にあります。
|
6
|
+
[ToggleButton クラス (System.Windows.Controls.Primitives) | Microsoft Docs](https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.controls.primitives.togglebutton)
|
7
|
+
|
8
|
+
わかっておられるでしょうが、これは`CheckBox`のボタン版です。
|
9
|
+
それぞれにOn・Off状態があります。
|
10
|
+
|
11
|
+
そうではなく`RadioButton`のボタン版が欲しい場合は、スタイルを`ToggleButton`にするという大技?があります。
|
12
|
+
|
13
|
+
どちらもボタンの見た目な場合は、`ThreeState`は設定しないほうがいいでしょう。
|
14
|
+
まったく違いが判りません(自分でスタイルをいじる場合はその限りではありません)
|
15
|
+
|
16
|
+
|
17
|
+
> ボタンをクリックした場合、BackGroundまたはBorderを黄色にする
|
18
|
+
> クリックされなかったボタンはデフォルト色にする
|
19
|
+
|
20
|
+
スタイルをいじればどうとでもなりますが、何か理想の見た目がありますか?
|
21
|
+
|
22
|
+
```xml
|
23
|
+
<Window
|
24
|
+
x:Class="Questions353667.MainWindow"
|
25
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
26
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
27
|
+
SizeToContent="WidthAndHeight">
|
28
|
+
<StackPanel>
|
29
|
+
<GroupBox Header="CheckBox">
|
30
|
+
<StackPanel Orientation="Horizontal">
|
31
|
+
<CheckBox
|
32
|
+
MinWidth="50"
|
33
|
+
Content="C1"
|
34
|
+
IsChecked="True" />
|
35
|
+
<CheckBox
|
36
|
+
MinWidth="50"
|
37
|
+
Content="C2"
|
38
|
+
IsChecked="True" />
|
39
|
+
<CheckBox MinWidth="50" Content="C3" />
|
40
|
+
<CheckBox
|
41
|
+
MinWidth="50"
|
42
|
+
Content="C4"
|
43
|
+
IsChecked="{x:Null}"
|
44
|
+
IsThreeState="True" />
|
45
|
+
</StackPanel>
|
46
|
+
</GroupBox>
|
47
|
+
<GroupBox Header="ToggleButton">
|
48
|
+
<StackPanel Orientation="Horizontal">
|
49
|
+
<ToggleButton
|
50
|
+
MinWidth="50"
|
51
|
+
Content="B1"
|
52
|
+
IsChecked="True" />
|
53
|
+
<ToggleButton
|
54
|
+
MinWidth="50"
|
55
|
+
Content="B2"
|
56
|
+
IsChecked="True" />
|
57
|
+
<ToggleButton MinWidth="50" Content="B3" />
|
58
|
+
<ToggleButton
|
59
|
+
MinWidth="50"
|
60
|
+
Content="B4"
|
61
|
+
IsChecked="{x:Null}"
|
62
|
+
IsThreeState="True" />
|
63
|
+
</StackPanel>
|
64
|
+
</GroupBox>
|
65
|
+
<GroupBox Header="RadioButton">
|
66
|
+
<StackPanel Orientation="Horizontal">
|
67
|
+
<RadioButton
|
68
|
+
MinWidth="50"
|
69
|
+
Content="R1"
|
70
|
+
IsChecked="True" />
|
71
|
+
<RadioButton MinWidth="50" Content="R2" />
|
72
|
+
<RadioButton MinWidth="50" Content="R3" />
|
73
|
+
<RadioButton
|
74
|
+
MinWidth="50"
|
75
|
+
Content="R4"
|
76
|
+
IsChecked="{x:Null}"
|
77
|
+
IsThreeState="True" />
|
78
|
+
</StackPanel>
|
79
|
+
</GroupBox>
|
80
|
+
<GroupBox Header="RadioButton(Button Style)">
|
81
|
+
<StackPanel Orientation="Horizontal">
|
82
|
+
<RadioButton
|
83
|
+
MinWidth="50"
|
84
|
+
Content="B1"
|
85
|
+
IsChecked="True"
|
86
|
+
Style="{StaticResource {x:Type ToggleButton}}" />
|
87
|
+
<RadioButton
|
88
|
+
MinWidth="50"
|
89
|
+
Content="B2"
|
90
|
+
Style="{StaticResource {x:Type ToggleButton}}" />
|
91
|
+
<RadioButton
|
92
|
+
MinWidth="50"
|
93
|
+
Content="B3"
|
94
|
+
Style="{StaticResource {x:Type ToggleButton}}" />
|
95
|
+
<RadioButton
|
96
|
+
MinWidth="50"
|
97
|
+
Content="B4"
|
98
|
+
IsChecked="{x:Null}"
|
99
|
+
IsThreeState="True"
|
100
|
+
Style="{StaticResource {x:Type ToggleButton}}" />
|
101
|
+
</StackPanel>
|
102
|
+
</GroupBox>
|
103
|
+
</StackPanel>
|
104
|
+
</Window>
|
105
|
+
```
|
106
106
|

|