2010-09-09 98 views
1

做了一个非常简单的例子列表界面性能,希望有人能遵循这一点,并帮助我Expression Blend的绑定列表不绑定

这里是我的代码。

视图模型

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; 
    } 

} 

IPerson

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

查看

<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"> 
<Grid d:DataContext="{d:DesignInstance local:ViewModel}"> 

</Grid> 
</Window> 

在Expression Blend中,如果插入文本块,请单击“高级选项” - >数据绑定... - >数据上下文我将InterfacePerson和NonInterfacePerson视为绑定到的选项。但是,NonInterfacePerson有一个小箭头显示我可以绑定到的其他属性。年龄和名字在这种情况下。

当我将d:DataContext设置为d:DesignData Source时,会发生同样的情况。我没有用这个例子,因为它比较复杂。但那是我真正想要这个工作的地方,因为那时我可以看到我所有的绑定选项并且有样本数据。

如果我不是做这在我的观点:

<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显示它们的问题,因此设置绑定更容易。

感谢您提供的任何帮助!

回答

1

我很确定他们使用反射来识别对象的属性,而接口只是布局的描述,而不是真实的对象,所以没有反射的属性。

希望这会有所帮助。