【问题标题】:Dynamic DataGrid columns with Caliburn.micro带有 Caliburn.micro 的动态 DataGrid 列
【发布时间】:2018-10-09 07:03:46
【问题描述】:

我正在开发翻译工具,因此我想在我的数据库中显示(和编辑)翻译数据。但是现在我已经被数据的显示卡住了。

我使用 Caliburn.micro 作为框架。

数据由后端在List<List<string>> 中传递到前端,其中“外部”列表代表不同的短语,内部列表代表一行,第一列是原始文本,每一列是翻译每种语言。语言表示在一个额外的列表中(即第一个表中的一行是car|Auto|voiture,语言表示是de-DE|fr-FR。源语言是固定的。)

现在的问题是,当我将列表打包到IObservableCollection<List<string>> 中时,数据网格只显示两列:容量和计数。不幸的是,我不能将所有数据放在一个固定的对象中,因为语言不固定,这意味着我可以拥有 30 个甚至 100 个。

有没有人知道我该如何完成这项工作?

观点:

<UserControl x:Class="TranslationTool.EditDatabaseView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:TranslationTool"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <DataGrid ItemsSource="{Binding TranslationData}">

        </DataGrid>
    </Grid>
</UserControl>

视图模型:

class EditDatabaseViewModel : Screen
{
    private IObservableCollection<List<string>> _translationData;

    public EditDatabaseViewModel()
    {
         TranslationData = new BindableCollection<List<string>>(DataStore.DB.GetTranslationsGrid());
    }

    public IObservableCollection<List<string>> TranslationData
    {
        get
        {
            return _translationData;
        }
        set
        {
            _translationData = value;
            NotifyOfPropertyChange();
        }
    }
}

【问题讨论】:

  • 创建一个动态列数的DataTable并绑定到这个?
  • @mm8,原来如此简单...谢谢!

标签: c# wpf mvvm caliburn.micro


【解决方案1】:

正如@mm8 所写:将DataTable 绑定到DataGrid 就像一个魅力!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-04
    • 1970-01-01
    • 2011-01-09
    • 1970-01-01
    • 2013-10-26
    • 2017-12-11
    • 2020-08-10
    相关资源
    最近更新 更多