sách gpt4 ai đã đi

c# - WPF 中的便笺项目。模型、 View 、 View 模型

In lại 作者:行者123 更新时间:2023-12-03 10:48:45 33 4
mua khóa gpt4 Nike

我正在开发一个 Sticky Notes 项目并在 WPF 中做 UI,显然将 MVVM 作为我的架构设计选择。我正在重新考虑我的模型、 View 和 View 模型应该是什么。

我有一个名为 Note 的类,如下所示:

class Note
{
public Guid ID { get; set; }
public string Note { get; set; }
}

我也有用户,它存储笔记的集合:
public class User
{
public Guid ID { get; set; }
public Dictionary Notes = new Dictionary();
}

所以现在我需要制作我的模型和 View 模型。首先,我想采用最明显的方法,即 Note 本身就是 Model,然后为 ViewModel 设置一个 NoteViewModel。但是后来我想,如果我将 User 作为模型并为 ViewModel 提供一个 UserViewModel 类会怎样。如果我这样做了,我该如何实现 INotifyPropertyChanged。如果我的模型是 Note,INotifyPropertyChanged 的实现很简单。您对此的想法将不胜感激。

1 Câu trả lời

我认为你需要拓宽你对模型的看法。简而言之:
模型是您将使用的“对象”的表示(可以是带有表的数据库或您定义的 POCO)。 User 和 Note 都可能是模型的一部分,就像 一样。客户表和 客户订单 表是数据库中模型的一部分。 ViewModel 处理与模型交互的业务逻辑,并通过 wpf 属性绑定(bind)将该数据公开给 View 。

至于INotifyPropertCHanged,这里有一个简单的用法(vb):

Imports System.ComponentModel

Public Property CustomerName() As String
Get
Return Me.customerNameValue
End Get

Set(ByVal value As String)
If Not (value = customerNameValue) Then
Me.customerNameValue = value
NotifyPropertyChanged()
End If
End Set
End Property

C#:
 using System.ComponentModel

public string CustomerName
{
lấy
{
return this.customerNameValue;
}

bộ
{
if (value != this.customerNameValue)
{
this.customerNameValue = value;
NotifyPropertyChanged();
}
}
}

希望这可以帮助

关于c# - WPF 中的便笺项目。模型、 View 、 View 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15347025/

33 4 0
Bài viết được đề xuất: wpf - WPF错误处理多语言
Bài viết được đề xuất: WPF:使用哪个集合类
Bài viết được đề xuất: c# - 在哪里保存我想在多个 ViewModel 之间共享的对象实例
Bài viết được đề xuất: wpf - 如何处理MVVM中的多个窗口和对话框?
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com