【发布时间】:2019-10-06 19:34:38
【问题描述】:
我的方法有问题。 我有复选框可以将变量的值更改为真/假。
我的变量 Prise1、Prise2、Prise3 和 Prise4 位于一侧,另一侧位于一周的 7 天。
我必须完成与所选日期相关的请求。例如:
在截图上,我想修改以下信息:
- “prise1”的星期二、星期三
- “prise2”没有任何内容
- “prise3”的周五和周日
- “持续时间”的星期四
我想到了一个二维表,我可以通过它来检查值是真还是假,但我真的不知道该怎么做。
编辑: 我错过了什么 ?绑定不起作用,当我检查我没有进入“设置”时。
public class WeekValues : ObservableObject
{
public bool Monday { get; set; }
public bool Tuesday { get; set; }
public bool Wednesday { get; set; }
public bool Thursday { get; set; }
public bool Friday { get; set; }
public bool Saturday { get; set; }
public bool Sunday { get; set; }
}
对于视图模型:
private WeekValues _Prise1;
public WeekValues Prise1
{
get
{
return _Prise1;
}
set
{
if (value != _Prise1)
{
_Prise1 = value;
RaisePropertyChanged(nameof(Prise1));
}
}
}
private WeekValues _Prise2;
public WeekValues Prise2
{
get
{
return _Prise2;
}
set
{
if (value != _Prise2)
{
_Prise2 = value;
RaisePropertyChanged(nameof(Prise2));
}
}
}
和 WPF:
<StackPanel HorizontalAlignment="Center" Grid.Row="1" Grid.Column="2">
<CheckBox Margin="0,9,0,5" IsChecked="{Binding Prise1}"></CheckBox>
<CheckBox Margin="0,10,0,5" IsChecked="{Binding Prise2.Monday}"></CheckBox>
<CheckBox Margin="0,10,0,5"></CheckBox>
<CheckBox Margin="0,9,0,0"></CheckBox>
</StackPanel>
<Label Grid.Row="0" Grid.Column="3" HorizontalAlignment="Center" FontWeight="Bold">M</Label>
<StackPanel HorizontalAlignment="Center" Grid.Row="1" Grid.Column="3">
<CheckBox Margin="0,9,0,5" IsChecked="{Binding Prise1.Tuesday}"></CheckBox>
<CheckBox Margin="0,10,0,5" IsChecked="{Binding Prise2.Tuesday}"></CheckBox>
<CheckBox Margin="0,10,0,5"></CheckBox>
<CheckBox Margin="0,9,0,0"></CheckBox>
</StackPanel>
提前谢谢你
【问题讨论】:
-
是 windows 窗体还是 wpf?
-
它是 wpf,带有 MVVM