我想问你,当我改变源代码的时候,我如何在视图上反映变化。这是我的密码。模型:
public class ExecutionMode
{
private List<DayItem> _dayItems = new List<DayItem>();
public enum TypeMode
{
None,
Once,
Daily,
Weekly
}
public TypeMode Mode { get; set; }
public DateTime? ExecutionTime { get; set; }
public DateTime? ExecutionDate { get; set; }
public List<DayItem> DayItems { get { return _dayItems; } set { _dayItems = value; } }
}
public class ProfileRecord
{
private ExecutionMode _mode = new ExecutionMode();
public ExecutionMode ExecutionMode { get { return _mode; } set { _mode = value; } }
}ViewModel
public class NewProfileViewModel : INotifyPropertyChanged
{private ProfileRecord _record = new ProfileRecord();
public ProfileRecord Record { get{return _record; } set{_record=value; OnPropertyChanged("Record")}}XAML:
<toolkit:TimePicker Header="Time of execution:" Margin="12,0,70,0" Value="{Binding ProfileRecord.ExecutionMode.ExecutionTime, Mode=TwoWay}" Visibility="{Binding ElementName=lpickerExecutionModes, Path=SelectedItem, Converter={StaticResource VisibilityConvert}, ConverterParameter=Once|Daily|Weekly}" />当我在代码Record.ExecutionTime = Time中设置时,它不会考虑视图。所以我在问。我也应该在模型中实现NotifyPropertyChanged吗?谢谢
发布于 2013-03-13 08:43:20
解决这个问题的方法有两种:
INotifyPropertyChangedViewModel中的属性,并在这些属性上实现INotifyPropertyChanged。我更喜欢第一种方法,特别是当模型非常庞大的时候,它有很多属性,并且所有这些属性都在View中使用。
https://stackoverflow.com/questions/15380426
复制相似问题