0
메모 및 텍스트 상자가있는 간단한 갤러리로 제목별로 새 갤러리를 추가합니다. mvvm을 사용하고 다른 바인딩이 올바로 작동합니다. 메모의 제목을 설정하고 속성 추가를 클릭하면 NewNote.Title이 업데이트되고 데이터베이스에 개체가 저장됩니다. 그 후 NewNote를 삭제합니다. 제목은 있지만 UI는 업데이트되지 않습니다. 여기 양방향 모드에서 Wpf 바인드 속성이 업데이트되지 않습니다.
짧은 비디오에게 있습니다 https://youtu.be/l3vFwI-a4TQXAML
<TextBox Text="{Binding NewNote.Title}" />
페이지 뷰 모델
class NotesPageViewModel : INotifyPropertyChanged
{
public ObservableCollection<NoteViewModel> Notes { get; set; }
public NoteViewModel NewNote { get; set; }
public NotesPageViewModel()
{
NewNote = new NoteViewModel();
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
internal void LoadNotes()
{
using (var uow = new UnitOfWork())
{
Notes.Clear();
uow.NotesRepository.OrderBy(n => n.Position).ToList()
.ForEach(note => Notes.Add((NoteViewModel)note));
}
}
internal void AddNote()
{
if (string.IsNullOrWhiteSpace(NewNote.Title))
return;
using (var uow = new UnitOfWork())
{
uow.NotesRepository.Add((Note)NewNote);
uow.Complete();
}
NewNote.Title = "";
LoadNotes();
}
}
개체보기 모델
class NoteViewModel : INotifyPropertyChanged
{
public int Id { get; set; }
public string Title { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
방금 환상적인 라이브러리를 찾았으므로 [ImplementPropertyChanged]를 클래스 선언에 배치 할 수 있습니다.이 클래스는 Fody –