使用属性更新标签绑定不是第一次设置正确

时间:2016-11-18 22:38:42

标签: wpf vb.net data-binding

我有一个简单的应用程序,我试图掌握绑定和属性。

我想做的事情: 从主窗口加载模态窗口。我知道这会阻止对它的所有访问,所以我试图通过属性绑定更新模态窗口上的标签。

我设置了datacontext:

   DataContext = busyupdate
   InitializeComponent()

设置变量:

Property busyupdate As BusyWindowGetSet = New BusyWindowGetSet

然后我将标签绑定到当前上下文:

Content="{Binding Stage, UpdateSourceTrigger=PropertyChanged}"
Content="{Binding Description, UpdateSourceTrigger=PropertyChanged}"

这是我的BusyWindowGetSet类,其中我有2个属性......舞台和描述。它实现了INotifyPropertyChanged

Imports System.ComponentModel

Public Class BusyWindowGetSet

    Implements INotifyPropertyChanged

    Public Property Stage() As String
        Get
            Return m_stage
        End Get
        Set(value As String)
            m_stage = value
            NotifyPropertyChanged("Stage")
        End Set
    End Property
    Private Shared m_Stage As String

    Public Property Description() As String
        Get
            Return m_description
        End Get
        Set(value As String)
            m_description = value
            NotifyPropertyChanged("Description")
        End Set
    End Property
    Private Shared m_Description As String

#Region "INotifyPropertyChanged Members"
    Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
#End Region

#Region "Private Helpers"
    Public Sub NotifyPropertyChanged(propertyName As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
    End Sub
#End Region

End Class

当我加载"忙碌窗口"标签没有更新..但如果我第二次加载窗口,它们会像正常一样显示和更改。

这就是我设置属性的方式......

busyupdate.Stage = String.Format("Stage: {0}", "Warming up1")
busyupdate.Description = String.Format("Description: {0}", "Warming up1")

我在这里缺少什么?

马克更新:

    Dim mm As New BusyWindow
    mm.ShowDialog()

    busyupdate.Stage = String.Format("Stage: {0}", "Warming up1")
    busyupdate.Description = String.Format("Description: {0}", "Warming up1")

0 个答案:

没有答案