回答編集履歴
2
見直しキャンペーン中
answer
CHANGED
@@ -1,306 +1,307 @@
|
|
1
|
-
たくさん回答も付いてるうえBAもされているようですが^^;
|
2
|
-
|
3
|
-
結局やりたいことって「問題の順番・選択肢の順番をランダムにしたい」ということですよね?
|
4
|
-
難しく考えすぎというか、外野であれこれしようとしすぎというか。
|
5
|
-
|
6
|
-
今回の場合は単に取得時に、都度シャッフルした配列・リストを返せばいいだけに見えます。
|
7
|
-
カテゴリもなぜ文字列で渡さなければならないかが、コードから読み取れません(リスト自体を渡せばいいだけでは?)
|
8
|
-
|
9
|
-
xamlがわからないので何とも言えませんが、`ItemsControl`等をうまく使うとコレクション内の個数を気にせず表示できます(回答は選択肢だけで使っていますが、カテゴリでも同じように作れます)
|
10
|
-
|
11
|
-
コードがないとイメージしにくそうなので、非常に雑ですがサンプルです(ファイル云々は省略)
|
12
|
-
|
13
|
-
MainWindow
|
14
|
-
```
|
15
|
-
<NavigationWindow
|
16
|
-
x:Class="Questions370911.MainWindow"
|
17
|
-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
18
|
-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
19
|
-
Width="800"
|
20
|
-
Height="450"
|
21
|
-
ShowsNavigationUI="False"
|
22
|
-
Source="/CategoryPage.xaml" />
|
23
|
-
```
|
24
|
-
|
25
|
-
```
|
26
|
-
using System;
|
27
|
-
using System.Collections.Generic;
|
28
|
-
using System.Linq;
|
29
|
-
|
30
|
-
namespace Questions370911
|
31
|
-
{
|
32
|
-
public class QuizData
|
33
|
-
{
|
34
|
-
public string Question { get; }
|
35
|
-
|
36
|
-
// プロパティにして取得のたびにシャッフルした配列を返す
|
37
|
-
public string[] Choices
|
38
|
-
{
|
39
|
-
get
|
40
|
-
{
|
41
|
-
return _Choices.OrderBy(_ => Guid.NewGuid()).ToArray();
|
42
|
-
}
|
43
|
-
}
|
44
|
-
// ↑↓同じ意味
|
45
|
-
//public string[] Choices => _Choices.OrderBy(_ => Guid.NewGuid()).ToArray();
|
46
|
-
|
47
|
-
public string Answer { get; }
|
48
|
-
|
49
|
-
private readonly string[] _Choices;
|
50
|
-
|
51
|
-
public QuizData(string question, params string[] choices)
|
52
|
-
{
|
53
|
-
Question = question;
|
54
|
-
_Choices = choices;
|
55
|
-
Answer = choices[0];
|
56
|
-
}
|
57
|
-
}
|
58
|
-
|
59
|
-
|
60
|
-
public partial class MainWindow // : Window
|
61
|
-
{
|
62
|
-
// ここも
|
63
|
-
public List<QuizData> A_QuizData => _A_QuizData.OrderBy(_ => Guid.NewGuid()).ToList();
|
64
|
-
public List<QuizData> B_QuizData => _B_QuizData.OrderBy(_ => Guid.NewGuid()).ToList();
|
65
|
-
public List<QuizData> C_QuizData => _C_QuizData.OrderBy(_ => Guid.NewGuid()).ToList();
|
66
|
-
|
67
|
-
private readonly List<QuizData> _A_QuizData = new List<QuizData>
|
68
|
-
{
|
69
|
-
new QuizData("史上初の家庭用ゲーム機とされるものは?", "オデッセイ(マグナボックス)", "ホーム・ポン(アタリ)", "カラーテレビゲーム15(任天堂)"),
|
70
|
-
new QuizData("ファミコンのコントローラーにはマイクが付いている?", "○", "×"),
|
71
|
-
new QuizData("スーパーファミコンソフト「ドラゴンクエスト6 幻の大地」の定価(税抜)は?", "11,400円", "14,800円", "9,700円", "5,980円"),
|
72
|
-
new QuizData("PlayStationの同時発売ソフトは?", "リッジレーサー(ナムコ)", "モータートゥーン・グランプリ(SCE)", "チョロQ(タカラ)"),
|
73
|
-
};
|
74
|
-
private readonly List<QuizData> _B_QuizData = new List<QuizData>
|
75
|
-
{
|
76
|
-
new QuizData("hogehoge", "A", "B", "C"),
|
77
|
-
};
|
78
|
-
private readonly List<QuizData> _C_QuizData = new List<QuizData>
|
79
|
-
{
|
80
|
-
new QuizData("fugafuga", "1", "2", "3", "4"),
|
81
|
-
};
|
82
|
-
|
83
|
-
|
84
|
-
public MainWindow() => InitializeComponent();
|
85
|
-
}
|
86
|
-
}
|
87
|
-
```
|
88
|
-
|
89
|
-
CategoryPage
|
90
|
-
```
|
91
|
-
<Page
|
92
|
-
x:Class="Questions370911.CategoryPage"
|
93
|
-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
94
|
-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
95
|
-
<UniformGrid Columns="3">
|
96
|
-
<Button Click="ButtonA_Click" Content="おじさんゲーマークイズ" />
|
97
|
-
<Button Click="ButtonB_Click" Content="hogehoge" />
|
98
|
-
<Button Click="ButtonC_Click" Content="fugafuga" />
|
99
|
-
</UniformGrid>
|
100
|
-
</Page>
|
101
|
-
```
|
102
|
-
|
103
|
-
```
|
104
|
-
using System.Windows;
|
105
|
-
using System.Windows.Controls;
|
106
|
-
using System.Windows.Navigation;
|
107
|
-
|
108
|
-
namespace Questions370911
|
109
|
-
{
|
110
|
-
public partial class CategoryPage : Page
|
111
|
-
{
|
112
|
-
// こうしてしまうと「今」表示しているMainWindowとは別のMainWindowを作ってしまっている!
|
113
|
-
//readonly MainWindow _main = new MainWindow();
|
114
|
-
private readonly MainWindow _main;
|
115
|
-
|
116
|
-
public CategoryPage()
|
117
|
-
{
|
118
|
-
InitializeComponent();
|
119
|
-
|
120
|
-
// 手軽にやるならこう
|
121
|
-
_main = (MainWindow)Application.Current.MainWindow;
|
122
|
-
}
|
123
|
-
|
124
|
-
private void ButtonA_Click(object sender, RoutedEventArgs e)
|
125
|
-
=> NavigationService.Navigate(new QuizPage(_main.A_QuizData));
|
126
|
-
private void ButtonB_Click(object sender, RoutedEventArgs e)
|
127
|
-
=> NavigationService.Navigate(new QuizPage(_main.B_QuizData));
|
128
|
-
private void ButtonC_Click(object sender, RoutedEventArgs e)
|
129
|
-
=> NavigationService.Navigate(new QuizPage(_main.C_QuizData));
|
130
|
-
}
|
131
|
-
}
|
132
|
-
```
|
133
|
-
|
134
|
-
QuizPage
|
135
|
-
```
|
136
|
-
<Page
|
137
|
-
x:Class="Questions370911.QuizPage"
|
138
|
-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
139
|
-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
140
|
-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
141
|
-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
142
|
-
d:DesignHeight="450"
|
143
|
-
d:DesignWidth="800"
|
144
|
-
mc:Ignorable="d">
|
145
|
-
<Page.Resources>
|
146
|
-
<Style TargetType="TextBlock">
|
147
|
-
<Setter Property="HorizontalAlignment" Value="Center" />
|
148
|
-
<Setter Property="VerticalAlignment" Value="Center" />
|
149
|
-
</Style>
|
150
|
-
<Style TargetType="Button">
|
151
|
-
<Setter Property="HorizontalAlignment" Value="Center" />
|
152
|
-
<Setter Property="VerticalAlignment" Value="Center" />
|
153
|
-
</Style>
|
154
|
-
</Page.Resources>
|
155
|
-
<Grid>
|
156
|
-
<!--
|
157
|
-
TabControlを使った深い意味はありません。
|
158
|
-
比較的シンプルでデザインも確認しやすいって程度です。
|
159
|
-
-->
|
160
|
-
<TabControl x:Name="tabControl" BorderThickness="0">
|
161
|
-
<TabItem Header="問題" Visibility="Collapsed">
|
162
|
-
<Grid>
|
163
|
-
<Grid.RowDefinitions>
|
164
|
-
<RowDefinition />
|
165
|
-
<RowDefinition />
|
166
|
-
</Grid.RowDefinitions>
|
167
|
-
<TextBlock x:Name="questionTextBlock" Text="問題文" />
|
168
|
-
<ItemsControl
|
169
|
-
x:Name="itemsControl"
|
170
|
-
Grid.Row="1"
|
171
|
-
HorizontalAlignment="Center"
|
172
|
-
VerticalAlignment="Center"
|
173
|
-
d:ItemsSource="{d:SampleData}"
|
174
|
-
Button.Click="AnswerButton_Click">
|
175
|
-
<ItemsControl.ItemsPanel>
|
176
|
-
<ItemsPanelTemplate>
|
177
|
-
<WrapPanel />
|
178
|
-
</ItemsPanelTemplate>
|
179
|
-
</ItemsControl.ItemsPanel>
|
180
|
-
<ItemsControl.ItemTemplate>
|
181
|
-
<DataTemplate>
|
182
|
-
<Button Margin="5" Content="{Binding}" />
|
183
|
-
</DataTemplate>
|
184
|
-
</ItemsControl.ItemTemplate>
|
185
|
-
</ItemsControl>
|
186
|
-
</Grid>
|
187
|
-
</TabItem>
|
188
|
-
|
189
|
-
<TabItem Header="正解" Visibility="Collapsed">
|
190
|
-
<Grid>
|
191
|
-
<Grid.RowDefinitions>
|
192
|
-
<RowDefinition />
|
193
|
-
<RowDefinition />
|
194
|
-
</Grid.RowDefinitions>
|
195
|
-
<TextBlock Text="正解" />
|
196
|
-
<Button
|
197
|
-
Grid.Row="1"
|
198
|
-
Click="NextButton_Click"
|
199
|
-
Content="次へ" />
|
200
|
-
</Grid>
|
201
|
-
</TabItem>
|
202
|
-
|
203
|
-
<TabItem Header="不正解" Visibility="Collapsed">
|
204
|
-
<Grid>
|
205
|
-
<Grid.RowDefinitions>
|
206
|
-
<RowDefinition />
|
207
|
-
<RowDefinition />
|
208
|
-
</Grid.RowDefinitions>
|
209
|
-
<TextBlock Text="不正解" />
|
210
|
-
<Button
|
211
|
-
Grid.Row="1"
|
212
|
-
Click="NextButton_Click"
|
213
|
-
Content="次へ" />
|
214
|
-
</Grid>
|
215
|
-
</TabItem>
|
216
|
-
|
217
|
-
<TabItem Header="成績" Visibility="Collapsed">
|
218
|
-
<Grid>
|
219
|
-
<Grid.RowDefinitions>
|
220
|
-
<RowDefinition />
|
221
|
-
<RowDefinition />
|
222
|
-
</Grid.RowDefinitions>
|
223
|
-
<TextBlock x:Name="resultTextBlock" Text="〇問中〇問正解" />
|
224
|
-
<Button
|
225
|
-
Grid.Row="1"
|
226
|
-
Click="BackButton_Click"
|
227
|
-
Content="戻る" />
|
228
|
-
</Grid>
|
229
|
-
</TabItem>
|
230
|
-
</TabControl>
|
231
|
-
</Grid>
|
232
|
-
</Page>
|
233
|
-
```
|
234
|
-
|
235
|
-
```
|
236
|
-
using System;
|
237
|
-
using System.Collections.Generic;
|
238
|
-
using System.Windows;
|
239
|
-
using System.Windows.Controls;
|
240
|
-
using System.Windows.Navigation;
|
241
|
-
|
242
|
-
namespace Questions370911
|
243
|
-
{
|
244
|
-
public partial class QuizPage : Page
|
245
|
-
{
|
246
|
-
private readonly List<QuizData> quizData;
|
247
|
-
private int index;
|
248
|
-
private int correct;
|
249
|
-
|
250
|
-
// わざわざ文字列でカテゴリを渡すより、直接リストをもらったほうが早いでしょう
|
251
|
-
// カテゴリ名も欲しければ、KOZ6.0さんの回答のようにクラスにまとめましょう
|
252
|
-
public QuizPage(List<QuizData> quizData)
|
253
|
-
{
|
254
|
-
InitializeComponent();
|
255
|
-
|
256
|
-
this.quizData = quizData;
|
257
|
-
|
258
|
-
questionTextBlock.Text = quizData[index].Question;
|
259
|
-
itemsControl.ItemsSource = quizData[index].Choices;
|
260
|
-
tabControl.SelectedIndex = 0;
|
261
|
-
}
|
262
|
-
|
263
|
-
private void AnswerButton_Click(object sender, RoutedEventArgs e)
|
264
|
-
{
|
265
|
-
if (e.OriginalSource is Button button)
|
266
|
-
{
|
267
|
-
if ((string)button.Content == quizData[index].Answer)
|
268
|
-
{
|
269
|
-
tabControl.SelectedIndex = 1;
|
270
|
-
correct++;
|
271
|
-
}
|
272
|
-
else
|
273
|
-
{
|
274
|
-
tabControl.SelectedIndex = 2;
|
275
|
-
}
|
276
|
-
|
277
|
-
index++;
|
278
|
-
}
|
279
|
-
}
|
280
|
-
|
281
|
-
private void NextButton_Click(object sender, RoutedEventArgs e)
|
282
|
-
{
|
283
|
-
if (index < quizData.Count)
|
284
|
-
{
|
285
|
-
questionTextBlock.Text = quizData[index].Question;
|
286
|
-
itemsControl.ItemsSource = quizData[index].Choices;
|
287
|
-
tabControl.SelectedIndex = 0;
|
288
|
-
}
|
289
|
-
else
|
290
|
-
{
|
291
|
-
resultTextBlock.Text = $"{quizData.Count}問中{correct}問正解";
|
292
|
-
tabControl.SelectedIndex = 3;
|
293
|
-
}
|
294
|
-
}
|
295
|
-
|
296
|
-
private void BackButton_Click(object sender, RoutedEventArgs e)
|
297
|
-
=> NavigationService.Navigate(new Uri("/CategoryPage.xaml", UriKind.Relative));
|
298
|
-
}
|
299
|
-
}
|
300
|
-
```
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
1
|
+
たくさん回答も付いてるうえBAもされているようですが^^;
|
2
|
+
|
3
|
+
結局やりたいことって「問題の順番・選択肢の順番をランダムにしたい」ということですよね?
|
4
|
+
難しく考えすぎというか、外野であれこれしようとしすぎというか。
|
5
|
+
|
6
|
+
今回の場合は単に取得時に、都度シャッフルした配列・リストを返せばいいだけに見えます。
|
7
|
+
カテゴリもなぜ文字列で渡さなければならないかが、コードから読み取れません(リスト自体を渡せばいいだけでは?)
|
8
|
+
|
9
|
+
xamlがわからないので何とも言えませんが、`ItemsControl`等をうまく使うとコレクション内の個数を気にせず表示できます(回答は選択肢だけで使っていますが、カテゴリでも同じように作れます)
|
10
|
+
|
11
|
+
コードがないとイメージしにくそうなので、非常に雑ですがサンプルです(ファイル云々は省略)
|
12
|
+
|
13
|
+
MainWindow
|
14
|
+
```xml
|
15
|
+
<NavigationWindow
|
16
|
+
x:Class="Questions370911.MainWindow"
|
17
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
18
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
19
|
+
Width="800"
|
20
|
+
Height="450"
|
21
|
+
ShowsNavigationUI="False"
|
22
|
+
Source="/CategoryPage.xaml" />
|
23
|
+
```
|
24
|
+
|
25
|
+
```cs
|
26
|
+
using System;
|
27
|
+
using System.Collections.Generic;
|
28
|
+
using System.Linq;
|
29
|
+
|
30
|
+
namespace Questions370911
|
31
|
+
{
|
32
|
+
public class QuizData
|
33
|
+
{
|
34
|
+
public string Question { get; }
|
35
|
+
|
36
|
+
// プロパティにして取得のたびにシャッフルした配列を返す
|
37
|
+
public string[] Choices
|
38
|
+
{
|
39
|
+
get
|
40
|
+
{
|
41
|
+
return _Choices.OrderBy(_ => Guid.NewGuid()).ToArray();
|
42
|
+
}
|
43
|
+
}
|
44
|
+
// ↑↓同じ意味
|
45
|
+
//public string[] Choices => _Choices.OrderBy(_ => Guid.NewGuid()).ToArray();
|
46
|
+
|
47
|
+
public string Answer { get; }
|
48
|
+
|
49
|
+
private readonly string[] _Choices;
|
50
|
+
|
51
|
+
public QuizData(string question, params string[] choices)
|
52
|
+
{
|
53
|
+
Question = question;
|
54
|
+
_Choices = choices;
|
55
|
+
Answer = choices[0];
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
public partial class MainWindow // : Window
|
61
|
+
{
|
62
|
+
// ここも
|
63
|
+
public List<QuizData> A_QuizData => _A_QuizData.OrderBy(_ => Guid.NewGuid()).ToList();
|
64
|
+
public List<QuizData> B_QuizData => _B_QuizData.OrderBy(_ => Guid.NewGuid()).ToList();
|
65
|
+
public List<QuizData> C_QuizData => _C_QuizData.OrderBy(_ => Guid.NewGuid()).ToList();
|
66
|
+
|
67
|
+
private readonly List<QuizData> _A_QuizData = new List<QuizData>
|
68
|
+
{
|
69
|
+
new QuizData("史上初の家庭用ゲーム機とされるものは?", "オデッセイ(マグナボックス)", "ホーム・ポン(アタリ)", "カラーテレビゲーム15(任天堂)"),
|
70
|
+
new QuizData("ファミコンのコントローラーにはマイクが付いている?", "○", "×"),
|
71
|
+
new QuizData("スーパーファミコンソフト「ドラゴンクエスト6 幻の大地」の定価(税抜)は?", "11,400円", "14,800円", "9,700円", "5,980円"),
|
72
|
+
new QuizData("PlayStationの同時発売ソフトは?", "リッジレーサー(ナムコ)", "モータートゥーン・グランプリ(SCE)", "チョロQ(タカラ)"),
|
73
|
+
};
|
74
|
+
private readonly List<QuizData> _B_QuizData = new List<QuizData>
|
75
|
+
{
|
76
|
+
new QuizData("hogehoge", "A", "B", "C"),
|
77
|
+
};
|
78
|
+
private readonly List<QuizData> _C_QuizData = new List<QuizData>
|
79
|
+
{
|
80
|
+
new QuizData("fugafuga", "1", "2", "3", "4"),
|
81
|
+
};
|
82
|
+
|
83
|
+
|
84
|
+
public MainWindow() => InitializeComponent();
|
85
|
+
}
|
86
|
+
}
|
87
|
+
```
|
88
|
+
|
89
|
+
CategoryPage
|
90
|
+
```xml
|
91
|
+
<Page
|
92
|
+
x:Class="Questions370911.CategoryPage"
|
93
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
94
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
95
|
+
<UniformGrid Columns="3">
|
96
|
+
<Button Click="ButtonA_Click" Content="おじさんゲーマークイズ" />
|
97
|
+
<Button Click="ButtonB_Click" Content="hogehoge" />
|
98
|
+
<Button Click="ButtonC_Click" Content="fugafuga" />
|
99
|
+
</UniformGrid>
|
100
|
+
</Page>
|
101
|
+
```
|
102
|
+
|
103
|
+
```cs
|
104
|
+
using System.Windows;
|
105
|
+
using System.Windows.Controls;
|
106
|
+
using System.Windows.Navigation;
|
107
|
+
|
108
|
+
namespace Questions370911
|
109
|
+
{
|
110
|
+
public partial class CategoryPage : Page
|
111
|
+
{
|
112
|
+
// こうしてしまうと「今」表示しているMainWindowとは別のMainWindowを作ってしまっている!
|
113
|
+
//readonly MainWindow _main = new MainWindow();
|
114
|
+
private readonly MainWindow _main;
|
115
|
+
|
116
|
+
public CategoryPage()
|
117
|
+
{
|
118
|
+
InitializeComponent();
|
119
|
+
|
120
|
+
// 手軽にやるならこう
|
121
|
+
_main = (MainWindow)Application.Current.MainWindow;
|
122
|
+
}
|
123
|
+
|
124
|
+
private void ButtonA_Click(object sender, RoutedEventArgs e)
|
125
|
+
=> NavigationService.Navigate(new QuizPage(_main.A_QuizData));
|
126
|
+
private void ButtonB_Click(object sender, RoutedEventArgs e)
|
127
|
+
=> NavigationService.Navigate(new QuizPage(_main.B_QuizData));
|
128
|
+
private void ButtonC_Click(object sender, RoutedEventArgs e)
|
129
|
+
=> NavigationService.Navigate(new QuizPage(_main.C_QuizData));
|
130
|
+
}
|
131
|
+
}
|
132
|
+
```
|
133
|
+
|
134
|
+
QuizPage
|
135
|
+
```xml
|
136
|
+
<Page
|
137
|
+
x:Class="Questions370911.QuizPage"
|
138
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
139
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
140
|
+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
141
|
+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
142
|
+
d:DesignHeight="450"
|
143
|
+
d:DesignWidth="800"
|
144
|
+
mc:Ignorable="d">
|
145
|
+
<Page.Resources>
|
146
|
+
<Style TargetType="TextBlock">
|
147
|
+
<Setter Property="HorizontalAlignment" Value="Center" />
|
148
|
+
<Setter Property="VerticalAlignment" Value="Center" />
|
149
|
+
</Style>
|
150
|
+
<Style TargetType="Button">
|
151
|
+
<Setter Property="HorizontalAlignment" Value="Center" />
|
152
|
+
<Setter Property="VerticalAlignment" Value="Center" />
|
153
|
+
</Style>
|
154
|
+
</Page.Resources>
|
155
|
+
<Grid>
|
156
|
+
<!--
|
157
|
+
TabControlを使った深い意味はありません。
|
158
|
+
比較的シンプルでデザインも確認しやすいって程度です。
|
159
|
+
-->
|
160
|
+
<TabControl x:Name="tabControl" BorderThickness="0">
|
161
|
+
<TabItem Header="問題" Visibility="Collapsed">
|
162
|
+
<Grid>
|
163
|
+
<Grid.RowDefinitions>
|
164
|
+
<RowDefinition />
|
165
|
+
<RowDefinition />
|
166
|
+
</Grid.RowDefinitions>
|
167
|
+
<TextBlock x:Name="questionTextBlock" Text="問題文" />
|
168
|
+
<ItemsControl
|
169
|
+
x:Name="itemsControl"
|
170
|
+
Grid.Row="1"
|
171
|
+
HorizontalAlignment="Center"
|
172
|
+
VerticalAlignment="Center"
|
173
|
+
d:ItemsSource="{d:SampleData}"
|
174
|
+
Button.Click="AnswerButton_Click">
|
175
|
+
<ItemsControl.ItemsPanel>
|
176
|
+
<ItemsPanelTemplate>
|
177
|
+
<WrapPanel />
|
178
|
+
</ItemsPanelTemplate>
|
179
|
+
</ItemsControl.ItemsPanel>
|
180
|
+
<ItemsControl.ItemTemplate>
|
181
|
+
<DataTemplate>
|
182
|
+
<Button Margin="5" Content="{Binding}" />
|
183
|
+
</DataTemplate>
|
184
|
+
</ItemsControl.ItemTemplate>
|
185
|
+
</ItemsControl>
|
186
|
+
</Grid>
|
187
|
+
</TabItem>
|
188
|
+
|
189
|
+
<TabItem Header="正解" Visibility="Collapsed">
|
190
|
+
<Grid>
|
191
|
+
<Grid.RowDefinitions>
|
192
|
+
<RowDefinition />
|
193
|
+
<RowDefinition />
|
194
|
+
</Grid.RowDefinitions>
|
195
|
+
<TextBlock Text="正解" />
|
196
|
+
<Button
|
197
|
+
Grid.Row="1"
|
198
|
+
Click="NextButton_Click"
|
199
|
+
Content="次へ" />
|
200
|
+
</Grid>
|
201
|
+
</TabItem>
|
202
|
+
|
203
|
+
<TabItem Header="不正解" Visibility="Collapsed">
|
204
|
+
<Grid>
|
205
|
+
<Grid.RowDefinitions>
|
206
|
+
<RowDefinition />
|
207
|
+
<RowDefinition />
|
208
|
+
</Grid.RowDefinitions>
|
209
|
+
<TextBlock Text="不正解" />
|
210
|
+
<Button
|
211
|
+
Grid.Row="1"
|
212
|
+
Click="NextButton_Click"
|
213
|
+
Content="次へ" />
|
214
|
+
</Grid>
|
215
|
+
</TabItem>
|
216
|
+
|
217
|
+
<TabItem Header="成績" Visibility="Collapsed">
|
218
|
+
<Grid>
|
219
|
+
<Grid.RowDefinitions>
|
220
|
+
<RowDefinition />
|
221
|
+
<RowDefinition />
|
222
|
+
</Grid.RowDefinitions>
|
223
|
+
<TextBlock x:Name="resultTextBlock" Text="〇問中〇問正解" />
|
224
|
+
<Button
|
225
|
+
Grid.Row="1"
|
226
|
+
Click="BackButton_Click"
|
227
|
+
Content="戻る" />
|
228
|
+
</Grid>
|
229
|
+
</TabItem>
|
230
|
+
</TabControl>
|
231
|
+
</Grid>
|
232
|
+
</Page>
|
233
|
+
```
|
234
|
+
|
235
|
+
```cs
|
236
|
+
using System;
|
237
|
+
using System.Collections.Generic;
|
238
|
+
using System.Windows;
|
239
|
+
using System.Windows.Controls;
|
240
|
+
using System.Windows.Navigation;
|
241
|
+
|
242
|
+
namespace Questions370911
|
243
|
+
{
|
244
|
+
public partial class QuizPage : Page
|
245
|
+
{
|
246
|
+
private readonly List<QuizData> quizData;
|
247
|
+
private int index;
|
248
|
+
private int correct;
|
249
|
+
|
250
|
+
// わざわざ文字列でカテゴリを渡すより、直接リストをもらったほうが早いでしょう
|
251
|
+
// カテゴリ名も欲しければ、KOZ6.0さんの回答のようにクラスにまとめましょう
|
252
|
+
public QuizPage(List<QuizData> quizData)
|
253
|
+
{
|
254
|
+
InitializeComponent();
|
255
|
+
|
256
|
+
this.quizData = quizData;
|
257
|
+
|
258
|
+
questionTextBlock.Text = quizData[index].Question;
|
259
|
+
itemsControl.ItemsSource = quizData[index].Choices;
|
260
|
+
tabControl.SelectedIndex = 0;
|
261
|
+
}
|
262
|
+
|
263
|
+
private void AnswerButton_Click(object sender, RoutedEventArgs e)
|
264
|
+
{
|
265
|
+
if (e.OriginalSource is Button button)
|
266
|
+
{
|
267
|
+
if ((string)button.Content == quizData[index].Answer)
|
268
|
+
{
|
269
|
+
tabControl.SelectedIndex = 1;
|
270
|
+
correct++;
|
271
|
+
}
|
272
|
+
else
|
273
|
+
{
|
274
|
+
tabControl.SelectedIndex = 2;
|
275
|
+
}
|
276
|
+
|
277
|
+
index++;
|
278
|
+
}
|
279
|
+
}
|
280
|
+
|
281
|
+
private void NextButton_Click(object sender, RoutedEventArgs e)
|
282
|
+
{
|
283
|
+
if (index < quizData.Count)
|
284
|
+
{
|
285
|
+
questionTextBlock.Text = quizData[index].Question;
|
286
|
+
itemsControl.ItemsSource = quizData[index].Choices;
|
287
|
+
tabControl.SelectedIndex = 0;
|
288
|
+
}
|
289
|
+
else
|
290
|
+
{
|
291
|
+
resultTextBlock.Text = $"{quizData.Count}問中{correct}問正解";
|
292
|
+
tabControl.SelectedIndex = 3;
|
293
|
+
}
|
294
|
+
}
|
295
|
+
|
296
|
+
private void BackButton_Click(object sender, RoutedEventArgs e)
|
297
|
+
=> NavigationService.Navigate(new Uri("/CategoryPage.xaml", UriKind.Relative));
|
298
|
+
}
|
299
|
+
}
|
300
|
+
```
|
301
|
+

|
302
|
+
|
303
|
+
---
|
304
|
+
|
305
|
+
それより`_main = new MainWindow();`のほうが気になります。
|
306
|
+
**今**表示している`MainWindow`とは別の`MainWindow`を作ってしまっています。
|
306
307
|
これでは無駄に何度もファイルを読むことになります。
|
1
クリーンしたら同じになってたw
answer
CHANGED
@@ -34,7 +34,13 @@
|
|
34
34
|
public string Question { get; }
|
35
35
|
|
36
36
|
// プロパティにして取得のたびにシャッフルした配列を返す
|
37
|
+
public string[] Choices
|
38
|
+
{
|
39
|
+
get
|
40
|
+
{
|
37
|
-
|
41
|
+
return _Choices.OrderBy(_ => Guid.NewGuid()).ToArray();
|
42
|
+
}
|
43
|
+
}
|
38
44
|
// ↑↓同じ意味
|
39
45
|
//public string[] Choices => _Choices.OrderBy(_ => Guid.NewGuid()).ToArray();
|
40
46
|
|