コントロールをページのプロパティに正常にバインドしました。バインドしているプロパティはクラスを返します。バインディングは機能しますが、プロパティをクラスの新しいインスタンスに設定した場合、UIは更新されません。
誰かがこの問題を解決するための正しい方向を指している可能性があります。私はINotifyPropertyChangedを実装しようとしましたが、これは機能しません。
コードは次のとおりです。
XAML-非常に基本的なことですが、その瞬間にラベルをプロパティにバインドしようとしています。
<Grid>
<Label Content="{Binding StudentName}"></Label>
<Button Width="100" Height="75" Click="Button_Click" ></Button>
</Grid>
C#
this.DataContext = parentWindow.SelectedStudent;
親ウィンドウC#ノート親ウィンドウはINotifyPropertyChangedを実装します
public event PropertyChangedEventHandler PropertyChanged;
public UCStudent SelectedStudent
{
get
{
if (_selectedStudent == null)
{
_selectedStudent = new UCStudent();
}
return _selectedStudent;
}
set
{
if (_selectedStudent != value)
{
_selectedStudent = value;
OnPropertyChanged("SelectedStudent");
}
}
}
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
問題は、SelectedStudentプロパティを新しく選択された学生に設定すると、バインディングが更新されないことです。