基于未知数据的MVVM模型 [英] MVVM Model based on unknown data

查看:78
本文介绍了基于未知数据的MVVM模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究开发业务应用程序以替换我们当前的数据库系统.

I am investigating the development of a business application to replace our current database system.

我一直在对WPF和MVVM进行一些研究,有些困惑.我了解了MVVM的基础知识,并使用带有已知数据模型的MVVM创建了一些基本应用程序.

I have been doing some research into WPF and MVVM and am a little confused. I get the basics of MVVM and have created a few basic apps using MVVM with a known data model.

我的问题是这个.

因为我们希望基于数据库进行开发并允许我们的用户创建数据的不同视图,所以直到用户选择所需的视图和字段,我们才知道数据模型的结构.

Because we are looking to develop based on a database and allow our users to create different views of the data, we will not know the structure of the data model until the user chooses which view and fields they require.

我们的进口商也是如此.我们导入的文件具有相同的结构,但是字段数会根据请求的内容而有所不同.

The same applies for our importer. The file we import is of the same structure but the number of fields can vary depending on what was requested.

在不知道数据结构的情况下如何为MVVM创建动态模型?

How would we create a dynamic Model for the MVVM when we do not know the data structure?

我知道这是一个相当基本的问题,但我正在尝试调查MVVM是否是正确的方法.

I know this is a fairly basic question but I am trying to investigate if MVVM is the right way to go.

我们将使用合同开发人员,但我们需要能够设置所需内容的背景.

We will be using contract developers but we need to be able to set the context of what we require.

预先感谢.

推荐答案

Dynamics crm允许最终用户动态定义实体和表单以对其进行编辑.

Dynamics crm allows the end user to dynamically define entities and forms to edit them.

我不知道您在做什么,但我知道至少有一个软件公司使用它来构建最终客户将要更改的系统.

I don't know what you're doing but I know at least one software house uses it to build systems the end customer will alter.

返回mvvm.

MVVM实际上是一种演示模式.

MVVM is a presentation pattern really.

您仍然可以使用数据表来获取数据,当然,您可以从任何位置选择*来创建数据.而且,您可以创建层来动态处理数据库内容.所有这些都与wpf无关,并且实际上不在该小组的讨论范围之内.

You can still use datatables to get data and of course you can select * from wherever to create those. And you could create layers handle the database stuff dynamically.  All of which is nothing to do with wpf and outside the scope of this group really.

您可能想阅读的内容是icustomtypeprovider.您可以使用此方法构建完全动态的对象集.也许以实施CRUD方法为基础.

The thing you might want to read up on is icustomtypeprovider.  You can build a totally dynamic set of objects using this.   Perhaps basing them on something implementing CRUD methods.

然后要考虑动态UI.

您可以使用反射来查看某些对象中的属性并构建控件.然后,您可以插入某种用户选择的字段列表机制,以将其首选项从本地文件或数据库中读取.

You can use reflection to look at properties in some object and build controls.  And you can plug in some sort of user picked these list of fields mechanism reading their preferences out a local file or database.

假设您想要动态外观.也许是高级用户".建立外观.您可以将其转换为xaml字符串,并将其存储在某处.在运行时使用xamlreader将其应用于控件.

Say you wanted a dynamic look.  Perhaps a "power user" builds the look and feel.  You can translate that into a xaml string and store it somewhere.  Apply it to a control at run time using xamlreader.

所以dg是一个没有样式的数据网格,我可以从磁盘上读取文件并对其应用样式:

So where dg is a datagrid which has no styling whatsoever I can read a file off disk and apply a style to it:

            StreamReader mysr = new StreamReader("mygrid.xaml");
            dg = XamlReader.Load(mysr.BaseStream) as DataGrid;

您可以将其存储在数据库中,而不是将其存储在磁盘上.

Instead of being a file on disk you could store that in a database of course.

但是我的文件如下:

<DataGrid 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

                  Name="dg" 
                  AutoGenerateColumns="False"  HorizontalAlignment="Left" 
                  VerticalAlignment="Top" 
                  Margin="2"
                  CanUserAddRows="True"
                  CanUserDeleteRows="True"
                  DockPanel.Dock="Top"
                  AlternationCount="2"
                  ItemsSource="{Binding}" >

  <DataGrid.Columns>
      <DataGridTextColumn Binding="{Binding Path=ColID, Mode=TwoWay}" Header="Id"  Width="*" />
      <DataGridTextColumn Binding="{Binding Path=FieldName}" Header="Field Name" Width="5*" />
      <DataGridComboBoxColumn SelectedItemBinding="{Binding Path=DataType}" Header="Data Type"  Width="Auto"  ItemsSource="{StaticResource ResourceKey=DataTypes}"   />
      <DataGridCheckBoxColumn Binding="{Binding Path=SeeInGrid}" Header="See In Grid" Width="Auto" />
      <DataGridTextColumn Binding="{Binding Path=ColOrder}" Header="Column Order"  Width="Auto" />
      <DataGridTextColumn Binding="{Binding Path=ColHeading}" Header="Column Heading"  Width="Auto" />
      <DataGridTextColumn Binding="{Binding Path=ColWidth}" Header="Column Width"  Width="Auto" />
   </DataGrid.Columns>
</DataGrid>

该数据网格可能已被动态添加到视图中.

And that datagrid could have perhaps been dynamically added to the View.

底线.

是的,mvvm仍然是动态视图的理想选择.

Yes, mvvm is still a good candidate for dynamic views.


这篇关于基于未知数据的MVVM模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆