Silverlight 4.0 使用vb.net的Silverlight

Silverlight 4.0 使用vb.net的Silverlight,silverlight-4.0,vb.net-2010,Silverlight 4.0,Vb.net 2010,各位专家:, 我正在使用VS2010、VB.NET、Silverlight 4。 我需要的2路数据绑定与VB类的UI控件的代码。请找到我的工作代码 xaml 末级 Address.vb 导入System.ComponentModel 公共课堂演讲 实现INotifyPropertyChanged Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.Propert

各位专家:, 我正在使用VS2010、VB.NET、Silverlight 4。 我需要的2路数据绑定与VB类的UI控件的代码。请找到我的工作代码

xaml 末级

Address.vb 导入System.ComponentModel

公共课堂演讲 实现INotifyPropertyChanged

Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged

Private _name As String
Private _address1 As String
Private _address2 As String
Private _city As String
Private _state As String
Private _zipcode As String

Public Sub OnPropertyChanged(ByVal e As PropertyChangedEventArgs)
    If PropertyChangedEvent IsNot Nothing Then
        RaiseEvent PropertyChanged(Me, e)
    End If
End Sub

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 Property Address1() As String
    Get
        Return _address1
    End Get
    Set(ByVal value As String)
        _address1 = value
        OnPropertyChanged(New PropertyChangedEventArgs("Address1"))
    End Set
End Property

Public Property Address2() As String
    Get
        Return _address2
    End Get
    Set(ByVal value As String)
        _address2 = value
        OnPropertyChanged(New PropertyChangedEventArgs("Address2"))
    End Set
End Property

Public Property City() As String
    Get
        Return _city
    End Get
    Set(ByVal value As String)
        _city = value
        OnPropertyChanged(New PropertyChangedEventArgs("City"))
    End Set
End Property

Public Property State() As String
    Get
        Return _state
    End Get
    Set(ByVal value As String)
        _state = value
        OnPropertyChanged(New PropertyChangedEventArgs("State"))
    End Set
End Property

Public Property Zipcode() As String
    Get
        Return _zipcode
    End Get
    Set(ByVal value As String)
        _zipcode = value
        OnPropertyChanged(New PropertyChangedEventArgs("Zipcode"))
    End Set
End Property

Public Sub New(ByVal name As String, ByVal address1 As String, ByVal address2 As String, ByVal city As String, ByVal state As String, ByVal zipcode As String)
    Me.Name = name
    Me.Address1 = address1
    Me.Address2 = address2
    Me.City = city
    Me.State = state
    Me.Zipcode = zipcode

End Sub
末级

亲切问候,,
Kumar将LayoutRoot的datacontext属性设置为您的地址。然后在xaml中执行以下操作:

<TextBox ... Text="{Binding Name}" />
VB简单地址类:

Public Class Address

    Private _name As String = "Some Text"

    Public Property Name() As String
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            _name = value
        End Set
    End Property
End Class

请注意,我只设置了一次DataContext,这是针对LayoutRoot的。

为了给您一个简单的示例,我添加了我的答案。您的代码隐藏已将LayoutRoot.DataContext设置为address,但已被注释掉。很好!我希望我的回答是有帮助的。
<TextBox ... Text="{Binding Name}" />
<UserControl x:Class="VBSLTest.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">
        <TextBox Height="23" HorizontalAlignment="Left" Margin="12,12,0,0" Name="TextBox1" VerticalAlignment="Top" Width="192" Text="{Binding Name}" />
    </Grid>
</UserControl>
Partial Public Class MainPage
    Inherits UserControl

    Public Sub New()
        InitializeComponent()
        Dim address As Address
        Address = New Address()
        LayoutRoot.DataContext = address
    End Sub

End Class
Public Class Address

    Private _name As String = "Some Text"

    Public Property Name() As String
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            _name = value
        End Set
    End Property
End Class