有以下代码:
public interface ITest
{
string St1 { get; }
}
public class Test:ITest
{
public string St1 { get { return "Interface Property"; } }
public string St2 { get { return "Descedent Property"; } }
}
public partial class MainWindow : Window
{
public ObservableCollection<ITest> TestColl = new ObservableCollection<ITest>();
public MainWindow()
{
TestColl.Add(new Test());
TestColl.Add(new Test());
InitializeComponent();
gridControl1.DataSource = TestColl;
}
}
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="382" Width="600" xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid">
<Grid>
<dxg:GridControl HorizontalAlignment="Left" Name="gridControl1" VerticalAlignment="Top" Height="262">
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="St1" />
<dxg:GridColumn FieldName="St2" />
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView Name="tableView1" />
</dxg:GridControl.View>
</dxg:GridControl>
</Grid>
</Window>
所以St1一切正常,但不显示St2。我猜因为网格不确定实际的运行时类型,并使用集合中声明的类型。有没有办法让这个样本有效? Standart WPF DataGrid正确解析属性名称。