回答編集履歴

1

見直しキャンペーン中

2023/07/28 16:16

投稿

TN8001
TN8001

スコア10004

test CHANGED
@@ -1,211 +1,106 @@
1
1
  > ボタンを横に並べ、
2
-
3
2
  > トグルボタンのように動作させたいと思っている。
4
-
5
3
  > できたら、どのボタンを押した状態なのかも把握したい。
6
4
 
7
-
8
-
9
5
  Zuishinさんが書いておられますが、トグルボタンは既にあります。
10
-
11
6
  [ToggleButton クラス (System.Windows.Controls.Primitives) | Microsoft Docs](https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.controls.primitives.togglebutton)
12
7
 
13
-
14
-
15
8
  わかっておられるでしょうが、これは`CheckBox`のボタン版です。
16
-
17
9
  それぞれにOn・Off状態があります。
18
-
19
-
20
10
 
21
11
  そうではなく`RadioButton`のボタン版が欲しい場合は、スタイルを`ToggleButton`にするという大技?があります。
22
12
 
23
-
24
-
25
13
  どちらもボタンの見た目な場合は、`ThreeState`は設定しないほうがいいでしょう。
26
-
27
14
  まったく違いが判りません(自分でスタイルをいじる場合はその限りではありません)
28
15
 
29
16
 
30
-
31
-
32
-
33
17
  > ボタンをクリックした場合、BackGroundまたはBorderを黄色にする
34
-
35
18
  > クリックされなかったボタンはデフォルト色にする
36
-
37
-
38
19
 
39
20
  スタイルをいじればどうとでもなりますが、何か理想の見た目がありますか?
40
21
 
41
-
42
-
43
- ```xaml
22
+ ```xml
44
-
45
23
  <Window
46
-
47
24
  x:Class="Questions353667.MainWindow"
48
-
49
25
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
50
-
51
26
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
52
-
53
27
  SizeToContent="WidthAndHeight">
54
-
55
28
  <StackPanel>
56
-
57
29
  <GroupBox Header="CheckBox">
58
-
59
30
  <StackPanel Orientation="Horizontal">
60
-
61
31
  <CheckBox
62
-
63
32
  MinWidth="50"
64
-
65
33
  Content="C1"
66
-
67
34
  IsChecked="True" />
68
-
69
35
  <CheckBox
70
-
71
36
  MinWidth="50"
72
-
73
37
  Content="C2"
74
-
75
38
  IsChecked="True" />
76
-
77
39
  <CheckBox MinWidth="50" Content="C3" />
78
-
79
40
  <CheckBox
80
-
81
41
  MinWidth="50"
82
-
83
42
  Content="C4"
84
-
85
43
  IsChecked="{x:Null}"
86
-
87
44
  IsThreeState="True" />
88
-
89
45
  </StackPanel>
90
-
91
46
  </GroupBox>
92
-
93
47
  <GroupBox Header="ToggleButton">
94
-
95
48
  <StackPanel Orientation="Horizontal">
96
-
97
49
  <ToggleButton
98
-
99
50
  MinWidth="50"
100
-
101
51
  Content="B1"
102
-
103
52
  IsChecked="True" />
104
-
105
53
  <ToggleButton
106
-
107
54
  MinWidth="50"
108
-
109
55
  Content="B2"
110
-
111
56
  IsChecked="True" />
112
-
113
57
  <ToggleButton MinWidth="50" Content="B3" />
114
-
115
58
  <ToggleButton
116
-
117
59
  MinWidth="50"
118
-
119
60
  Content="B4"
120
-
121
61
  IsChecked="{x:Null}"
122
-
123
62
  IsThreeState="True" />
124
-
125
63
  </StackPanel>
126
-
127
64
  </GroupBox>
128
-
129
65
  <GroupBox Header="RadioButton">
130
-
131
66
  <StackPanel Orientation="Horizontal">
132
-
133
67
  <RadioButton
134
-
135
68
  MinWidth="50"
136
-
137
69
  Content="R1"
138
-
139
70
  IsChecked="True" />
140
-
141
71
  <RadioButton MinWidth="50" Content="R2" />
142
-
143
72
  <RadioButton MinWidth="50" Content="R3" />
144
-
145
73
  <RadioButton
146
-
147
74
  MinWidth="50"
148
-
149
75
  Content="R4"
150
-
151
76
  IsChecked="{x:Null}"
152
-
153
77
  IsThreeState="True" />
154
-
155
78
  </StackPanel>
156
-
157
79
  </GroupBox>
158
-
159
80
  <GroupBox Header="RadioButton(Button Style)">
160
-
161
81
  <StackPanel Orientation="Horizontal">
162
-
163
82
  <RadioButton
164
-
165
83
  MinWidth="50"
166
-
167
84
  Content="B1"
168
-
169
85
  IsChecked="True"
170
-
171
86
  Style="{StaticResource {x:Type ToggleButton}}" />
172
-
173
87
  <RadioButton
174
-
175
88
  MinWidth="50"
176
-
177
89
  Content="B2"
178
-
179
90
  Style="{StaticResource {x:Type ToggleButton}}" />
180
-
181
91
  <RadioButton
182
-
183
92
  MinWidth="50"
184
-
185
93
  Content="B3"
186
-
187
94
  Style="{StaticResource {x:Type ToggleButton}}" />
188
-
189
95
  <RadioButton
190
-
191
96
  MinWidth="50"
192
-
193
97
  Content="B4"
194
-
195
98
  IsChecked="{x:Null}"
196
-
197
99
  IsThreeState="True"
198
-
199
100
  Style="{StaticResource {x:Type ToggleButton}}" />
200
-
201
101
  </StackPanel>
202
-
203
102
  </GroupBox>
204
-
205
103
  </StackPanel>
206
-
207
104
  </Window>
208
-
209
105
  ```
210
-
211
106
  ![アプリ画像](a0c1cf8b61f97e2989b5a52af4c87036.png)