2009-09-15 167 views
1

嗯,我有这样的代码在我后面的代码Silverlight中的数据绑定

Public Shared ReadOnly UsernameProperty As DependencyProperty = DependencyProperty.Register("Username", GetType(String), GetType(LoginControl), Nothing) 

    Public Property Username() As String 
     Get 
      Return CStr(MyBase.GetValue(UsernameProperty)) 
     End Get 
     Set(ByVal value As String) 
      MyBase.SetValue(UsernameProperty, value) 
     End Set 
    End Property 

,然后我有这个在XAML同一页面

<TextBlock Text="{Binding Path=Username}" Style="{StaticResource WelcomeTextStyle}"/> 

上,但该文本块似乎没有更新它的值。

回答

1

您将路径设置为“用户名”,但绑定需要知道在哪个对象上查找该属性。 执行此操作的一种方法是,将DataContext设置为LoginControl。