wpf vb.netプロジェクトを作成し、簡単なデータを設定しようとしています。DataContext=this;を設定する方法がわかりません。コードバインドで。現在、プログラムを実行すると、ラベルが更新されません。以下にコードを含めました。私は何が欠けていますか?
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Label Content="{Binding person.Name}"/>
</Grid>
</Window>
Class MainWindow
Private Property person As New Person()
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
person.Name = "Poco"
End Sub
End Class
System.ComponentModel
Public Class Person
Implements INotifyPropertyChanged
Private _name As String
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
OnPropertyChanged(New PropertyChangedEventArgs("Name"))
End Set
End Property
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Public Sub OnPropertyChanged(ByVal e As PropertyChangedEventArgs)
If Not PropertyChangedEvent Is Nothing Then
RaiseEvent PropertyChanged(Me, e)
End If
End Sub
End Class