WPF中的MVVM数据绑定 [英] MVVM Data Binding in WPF

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

问题描述

我在WPF中有一个窗口,其中有类似
的文本框
StockName
StockGroup
数量
评分
单位

现在,我不想在代码隐藏"中编写任何代码,但是我想创建一个类,并且我在此窗口中修改的任何内容都应反映在该类中.

当我单击窗口中的保存"按钮时,应将所有数据从该类插入数据库..我该怎么做..

当我看到一些MVVM项目时,我感到很困惑..谁能给我一个简单的WPF中的MVVM示例.

I have a window in WPF which have textbox like

StockName
StockGroup
Quantity
Rate
Unit

Now i dont want to write any code in Code Behind but i want to create a class and any thing i modify in this window should be reflected in that class

When i click on the save button in my window, all the datas should be inserted into the database from the class.. HOw can i do that..

When i have seen some MVVM Projects i got confused.. Can anyone give me a simple example of MVVM in WPF

推荐答案

如果正确实现了MVVM,则数据模型应该包含已编辑"的值,您应该能够将它们保存到数据库中.

这是MVVM上的几个良好的启动链接
WPF:简化MVVM(模型视图视图模型) [ WPF/MVVM快速入门指南 [
If you have implemented MVVM correctly, your data model should contain the ''edited'' values and you should just be able to save them to the database.

Here are a couple of good startup links on MVVM
WPF: MVVM (Model View View-Model) Simplified[^]
WPF/MVVM Quick Start Tutorial[^]


如果您查看 ^ ]-您会发现一个简单的MVVM实现,它不使用大量外部库来构建MVVM类型的应用程序.

最好的问候
Espen Harlinn
If you look at the code for Depends4Net - Part 1[^] - you''ll find a straightforward MVVM implementation that does not use a bunch of external libraries to build an MVVM type of application.

Best regards
Espen Harlinn


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

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