我想问你,当我更改源时,如何在 View 上反映更改。这是我的代码。模型:
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; } }
}
视图模型
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 中设置某处时,它不会反映在 View 上。所以我在问。我也应该在模型中实现 NotifyPropertyChanged 吗?谢谢