【发布时间】:2019-09-26 11:13:01
【问题描述】:
我们有一个GridControl,我们将ItemsSource 分配给一个界面项的集合。集合中使用的接口继承自另一个接口,我们遇到的问题是只有在顶级接口中直接定义的项目才会显示在GridControl
下面是我们所看到的行为的一个非常简化的示例。
定义GridControl的xaml代码
<Window x:Class="WpfThrowaway.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:WpfThrowaway"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<dxg:GridControl x:Name="DataGrid" Background="#363636" Foreground="#FFFFFF" EnableSmartColumnsGeneration="True" AutoGenerateColumns="AddNew">
<dxg:GridControl.View >
<dxg:TableView x:Name="TableView" AllowEditing="False" />
</dxg:GridControl.View>
</dxg:GridControl>
</Grid>
</Window>
具体项目实现
class ConcreteItem : ILevel1
{
public string Level1String => "Level 1 string";
public double Level2Double => 2;
}
1 级接口(@987654329@ 集合中使用的类型)
interface ILevel1 : ILevel2
{
string Level1String { get; }
}
二级接口
interface ILevel2
{
double Level2Double { get; }
}
在MainWindow中初始化ItemsSource的代码
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var concreteItemCollection = new List<ILevel1>();
for(var i = 0; i < 100; i++)
{
concreteItemCollection.Add(new ConcreteItem());
}
DataGrid.ItemsSource = concreteItemCollection;
}
}
结果数据网格
我们想要并且期望GridControl 显示两列Level1String 和Level2Double,但只有在ILevel1 接口中明确定义的项目才会显示在网格中。
有什么解决方法吗?我们如何让继承接口的所有属性也显示出来?
【问题讨论】:
标签: devexpress-wpf devexpress-gridcontrol