Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.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
C# 表达式混合绑定列表不';t列出绑定的接口属性_C#_Wpf_Expression Blend - Fatal编程技术网

C# 表达式混合绑定列表不';t列出绑定的接口属性

C# 表达式混合绑定列表不';t列出绑定的接口属性,c#,wpf,expression-blend,C#,Wpf,Expression Blend,举了一个简单得多的例子,希望有人能效仿并帮助我 这是我的密码 视图模型 public class ViewModel { private Person _noninterfacePerson; private IPerson _interfacePerson; public ViewModel() { _noninterfacePerson = new Person(); _interfacePerson = new Person

举了一个简单得多的例子,希望有人能效仿并帮助我

这是我的密码

视图模型

public class ViewModel
{
    private Person _noninterfacePerson;
    private IPerson _interfacePerson;

    public ViewModel()
    {
        _noninterfacePerson = new Person();
        _interfacePerson = new Person();
    }

    public Person NonInterfacePerson
    {
        get { return _noninterfacePerson; }
    }

    public IPerson InterfacePerson
    {
        get { return InterfacePerson; }
    }

}

public class Person : IPerson
{
    public Person()
    {

    }

    public string Name
    {
        get;
        set;
    }

    public int age
    {
        get;
        set;
    }

}
伊佩森

public interface IPerson
{
    int age { get; set; }
    string Name { get; set; }
}
看法


在Expression Blend中,如果插入文本块,请单击“高级选项”->数据绑定…->我认为InterfacePerson和NonInterfacePerson都是绑定到的选项。但是,NonInterfacePerson有一个小箭头,显示了我可以绑定到的其他属性。本例中的年龄和姓名

当我将d:DataContext设置为d:DesignData源时,也会发生同样的情况。我没有在这个例子中使用它,因为它更复杂。但这正是我真正希望它发挥作用的地方,因为这样我就可以看到所有的绑定选项并获得示例数据

如果我改为在我看来这样做:

<Window x:Class="WpfApplication2.MainWindow"
 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"
        xmlns:local="clr-namespace:WpfApplication2"
        mc:Ignorable="d"
 Title="MainWindow" Height="350" Width="525">
 <Window.Resources>
 <local:ViewModel x:Key="DummyVM"/>
 </Window.Resources>
 <Grid d:DataContext="{Binding Source={StaticResource DummyVM}}">

 </Grid>
</Window>

然后我可以看到InterfacePerson的属性,但是,我仍然无法使用d:DesignData轻松实现我想要的示例数据

应该注意的是,在所有情况下,如果我手动输入路径,它都可以正常工作。这纯粹是一个让Blend显示它们的问题,这样设置绑定就更容易了


感谢您在这方面提供的任何帮助

我很确定他们使用反射来识别对象的属性,而界面只是布局的描述,而不是真实对象,因此没有反射属性


希望这能有所帮助。

我很确定他们使用反射来识别对象的属性,界面只是对布局的描述,而不是真实对象,因此没有反射属性

希望这有帮助

<Window x:Class="WpfApplication2.MainWindow"
 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"
        xmlns:local="clr-namespace:WpfApplication2"
        mc:Ignorable="d"
 Title="MainWindow" Height="350" Width="525">
 <Window.Resources>
 <local:ViewModel x:Key="DummyVM"/>
 </Window.Resources>
 <Grid d:DataContext="{Binding Source={StaticResource DummyVM}}">

 </Grid>
</Window>