我有一个使用MVVM的WPF应用程序。我的ViewModel上的模型实例上绑定了一个布尔值的IsChecked值。我还需要将ViewModel上的方法绑定到Checked和Unchecked事件。 (这是这样我就可以跟踪未保存的更改和改变背景给我的用户需要保存视觉指示我想:复选框上的双重绑定
<CheckBox
Content="Enable"
Margin="5"
IsChecked="{Binding Enabled}"
Checked="{Binding ScheduleChanged}"
Unchecked="{Binding ScheduleChanged}"
/>
但我得到一个System.Windows.Data“上提供价值”。 ?结合“抛出一个异常”的错误建议
这里是我一起工作的型号:
public class Schedule : IEquatable<Schedule>
{
private DateTime _scheduledStart;
private DateTime _scheduledEnd;
private bool _enabled;
private string _url;
public DateTime ScheduledStart
{
get { return _scheduledStart; }
set
{
_scheduledStart = value;
}
}
public DateTime ScheduledEnd
{
get { return _scheduledEnd; }
set
{
if(value < ScheduledStart)
{
throw new ArgumentException("Scheduled End cannot be earlier than Scheduled Start.");
}
else
{
_scheduledEnd = value;
}
}
}
public bool Enabled
{
get { return _enabled; }
set { _enabled = value; }
}
public string Url
{
get { return _url; }
set { _url = value; }
}
public bool Equals(Schedule other)
{
if(this.ScheduledStart == other.ScheduledStart && this.ScheduledEnd == other.ScheduledEnd
&& this.Enabled == other.Enabled && this.Url == other.Url)
{
return true;
}
else
{
return false;
}
}
}
我的视图模型包含有一个ObservableCollection属性一个ItemsControl绑定到集合并生成。 list。所以我的ViewModel有点了解我的Model实例,b我不认为哪一个是不知道的。
谢谢你的答复。我有这个绑定工作,但是,我希望能够跟踪其他领域的价值变化。一个文本框和来自Xceed的几个DateTimePicker。所有这一切都是为了设置一个标志,用于触发背景颜色的变化,如果有事情发生变化并且保存按钮尚未被点击。 –
@AaronRumford我刚刚添加了更多的细节。您可以使用绑定到上面的IsDirty属性的样式DataTrigger来更改UI的外观。 – RQDQ