所以,我有幾乎相同的事情設置與文本框/列表框等,但它只是似乎並不與數據網格工作..DataGrid不更新時,項目屬性發生變化
所以,我有一個觀點包含dataGrid的索引。
我創建了一個IndexModel類如下:
public class IndexModel : INotifyPropertyChanged
{
private ObservableCollection<Schedule> _schedules;
public IndexModel(ObservableCollection<Schedule> schedules)
{
_schedules = schedules;
}
public ObservableCollection<Schedule> Schedules
{
get { return _schedules; }
set
{
_schedules = value;
OnPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
然後在我的IndexView創建IndexModel。
private ObservableCollection<Schedule> _schedules;
public Index(MainController controller)
{
_controller = controller;
InitializeComponent();
_schedules = controller.DatabaseController.GetSchedules() as ObservableCollection<Schedule>;
DataContext = new IndexModel(_schedules);
Log.Info($"UI Component {componentName} loaded succesfully",componentName, Source);
}
我創建的DataContext和XAML
ItemsSource="{Binding Path=Schedules, Mode=TwoWay, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}"
綁定它我甚至創建了一個簡單的空白。
Schedule selectedItem = (Schedule) dataGrid.SelectedItem;
selectedItem.Name = "Testing";
它更新的ObservableCollection但DataGrid不更新......
我通過計算器的所有問題的答案看上去等,但還是沒能解決我的問題..
public partial class Schedule
{
public int Id { get; set; }
[Required]
[StringLength(50)]
public string Name { get; set; }
public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; }
public virtual User User { get; set; }
[StringLength(256)]
public string Comment { get; set; }
[StringLength(256)]
public string Description { get; set; }
[Required]
public Priorities Priority { get; set; }
public virtual UpdaterObject Object { get; set; }
public virtual ICollection<ScheduleAction> ScheduleAction { get; set; }
啊..這是有道理的。我改變了INotifyProperty而不是INotifyCollectionChanged。我會用CollectionChanged試用它,並儘快給出更新 – Wkjjjj
@Wkjjjj什麼?你在說什麼?!基本上沒有任何理由實現'INotifyCollectionChanged'。你是否在說'Schedule'實現了'INotifyPropertyChanged'?如果是這樣的話,那麼問題就不是我認爲的問題了。 –
@Wkjjjj你可以分享'Schedule'的來源嗎? –