gpt4 book ai didi

c# - 带集合的 MVVM

转载 作者:行者123 更新时间:2023-11-30 15:02:07 25 4
gpt4 key购买 nike

如果我有一个模型应该包含一个集合,例如书 -> 作者

我该怎么做

喜欢:

public class Book
{
public string Title { get; set; }
public List<Author> Authors { get; set; }
}

或更像是:

public class Book
{
public string Title { get; set; }
public List<AuthorViewModel> Authors { get; set; }
}

这两者中哪一个是更常见的方法以及如何从 ViewModel 中获取 View ?

最佳答案

这个肯定是错的:

public class Book
{
public string Title { get; set; }
public List<AuthorViewModel> Authors { get; set; }
}

但这没问题:

public class BookViewModel
{
public string Title { get; set; }
public List<AuthorViewModel> AuthorModels { get; set; }
}

关于c# - 带集合的 MVVM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13010686/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com