Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
绑定到友元属性的WPF_Wpf_Data Binding_Binding - Fatal编程技术网

绑定到友元属性的WPF

绑定到友元属性的WPF,wpf,data-binding,binding,Wpf,Data Binding,Binding,我正在从事两个项目: 一个业务逻辑层,它是一个类库,包含我的所有对象和应用程序的业务规则(我将把它称为我的BLL) 使用BLL的WPF应用程序 BLL中的Person类(目前唯一的类)的作用域修饰符设置为Friend(与Public一致),我已允许WPF应用程序使用Runtime.CompilerServices.InternalsVisibleTo属性访问该类 WPF应用程序引用BLL并具有以下组件 其中的PersonViewModel类包装了BLL的Person类 MainWindow.xa

我正在从事两个项目:

  • 一个业务逻辑层,它是一个类库,包含我的所有对象和应用程序的业务规则(我将把它称为我的BLL)
  • 使用BLL的WPF应用程序
  • BLL中的Person类(目前唯一的类)的作用域修饰符设置为Friend(与Public一致),我已允许WPF应用程序使用Runtime.CompilerServices.InternalsVisibleTo属性访问该类

    WPF应用程序引用BLL并具有以下组件

  • 其中的PersonViewModel类包装了BLL的Person类
  • MainWindow.xaml(及其对应的MainWindow.xaml.vb文件)
  • 由于Person类是一个Friend,我被迫在PersonViewModel中创建属性,该属性也将Person类公开给MainWindow.xaml Friend

    问题是,当我运行应用程序时,person的name属性从未显示

    下面是BLL中的Person类(请注意,“WPFFriendTest”是WPF应用程序的程序集名称):

    这是我的MainWindow.xaml(此窗口没有代码):

    
    
    如何向XAML公开Friend属性,以便它显示该属性

    谢谢你抽出时间

    -Frinny

    我明白了

    我将PersonViewModel类设置为好友而不是Public,并将Person属性更改为Public。这允许XAML显示好友信息

    像这样:

    Imports BuisnessLogicLayer
    
    Friend Class PersonViewModel
        Private _person As Person
    
        'Friend Property Person As Person'
        Public Property Person As Person
            Get
                Return _person
            End Get
            Set(ByVal value As Person)
                _person = value
            End Set
        End Property
        Public Sub New()
            _person = New Person
        End Sub
    End Class
    
    再次感谢您抽出时间

    -Frinny

    我明白了

    我将PersonViewModel类设置为好友而不是Public,并将Person属性更改为Public。这允许XAML显示好友信息

    像这样:

    Imports BuisnessLogicLayer
    
    Friend Class PersonViewModel
        Private _person As Person
    
        'Friend Property Person As Person'
        Public Property Person As Person
            Get
                Return _person
            End Get
            Set(ByVal value As Person)
                _person = value
            End Set
        End Property
        Public Sub New()
            _person = New Person
        End Sub
    End Class
    
    再次感谢您抽出时间

    -弗里尼

    <Window x:Class="MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:wpfFriendTest="clr-namespace:WPFFriendTest"
            Title="MainWindow" Height="350" Width="525">
        <StackPanel>
            <StackPanel.Resources>
                <wpfFriendTest:PersonViewModel x:Key="personVM"></wpfFriendTest:PersonViewModel>
            </StackPanel.Resources>
            <StackPanel Orientation="Horizontal" DataContext="{StaticResource personVM}">
                <Label Content="Name: "></Label>
                <TextBox Text="{Binding Person.Name}" Width="200"></TextBox>
            </StackPanel>
        </StackPanel>
    </Window>
    
    Imports BuisnessLogicLayer
    
    Friend Class PersonViewModel
        Private _person As Person
    
        'Friend Property Person As Person'
        Public Property Person As Person
            Get
                Return _person
            End Get
            Set(ByVal value As Person)
                _person = value
            End Set
        End Property
        Public Sub New()
            _person = New Person
        End Sub
    End Class