teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

4

コード修正

2019/03/09 14:15

投稿

cpthgli
cpthgli

スコア76

answer CHANGED
@@ -61,6 +61,7 @@
61
61
  else
62
62
  {
63
63
  checkBox.IsChecked = true;
64
+ checkBox.IsEnabled = false;
64
65
  // ポイント減少
65
66
  }
66
67
  }

3

ポイント判定の修正、スタイルの修正

2019/03/09 14:14

投稿

cpthgli
cpthgli

スコア76

answer CHANGED
@@ -51,16 +51,19 @@
51
51
  if (child is CheckBox checkBox) // objectからCheckBoxに型変換
52
52
  {
53
53
  if (checkBox.Tag is int time) // タグ付けした時間を取得
54
- {
54
+            {
55
55
  if (time < now.Hour)
56
56
  {
57
+ if(checkBox.IsChecked == true)
58
+ {
59
+ // ポイント増加
60
+ }
61
+ else
62
+ {
57
- checkBox.IsChecked = true;
63
+ checkBox.IsChecked = true;
58
- // ポイント減少
64
+ // ポイント減少
65
+ }
59
66
  }
60
- else
61
- {
62
- // ポイント増加
63
- }
64
67
  }
65
68
  }
66
69
  }
@@ -92,6 +95,7 @@
92
95
  <Style TargetType="CheckBox">
93
96
  <Setter Property="Margin" Value="5"/>
94
97
  <Setter Property="FontSize" Value="16"/>
98
+ <Setter Property="VerticalContentAlignment" Value="Center"/>
95
99
  </Style>
96
100
  </WrapPanel.Resources>
97
101
  </WrapPanel>

2

XAMLから不要な要素を削除

2019/03/09 14:13

投稿

cpthgli
cpthgli

スコア76

answer CHANGED
@@ -75,7 +75,6 @@
75
75
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
76
76
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
77
77
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
78
- xmlns:local="clr-namespace:CheckManager"
79
78
  mc:Ignorable="d"
80
79
  Title="MainWindow" Height="400" Width="800" Loaded="Window_Loaded">
81
80
  <Grid>

1

説明の追加

2019/03/09 14:05

投稿

cpthgli
cpthgli

スコア76

answer CHANGED
@@ -1,5 +1,8 @@
1
1
  Q71さんの回答より`Tag`プロパティなる便利なものを知ったので、勉強がてら使ってみました。
2
2
 
3
+ 特定のコンポーネント内のすべての子要素処理をするときは、その入れ物に`x:Name`をつけて`Children`プロパティから取得するのをよく使います。
4
+ これに`Tag`を組み合わせると、自動生成した場合でもそれぞれを容易に識別できるので便利ですね。
5
+
3
6
  ```C#
4
7
  // MainWIndow.xaml.cs
5
8
  public partial class MainWindow : Window