MVVM - 具有导航和可混合性的主/详细场景

发布于 2024-09-01 17:41:01 字数 350 浏览 3 评论 0原文

我将从我想要的开始,这样可能更容易理解:

  1. 我有一个页面(Master.xaml),其中有一个 PersonViewModel 列表框。
  2. 当用户从列表框中选择 PersonViewModel 时,我想导航到所选 PersonViewModel 的详细信息 (Details.xaml) 页面。
  3. 详细信息页面做了一些额外的繁重工作,我只想在用户导航到该页面时完成这些工作。 (我不想在主列表框的每个 PersonViewModel 中加载太多内容)

那么你们如何通过导航处理主/详细场景,同时保持“可混合性”?

过去一周我一直在兜圈子。对于应该很常见的事情似乎没有干净的解决方案?

I'll start off with what I want so it may be simpler to understand:

  1. I have a Page (Master.xaml) that has has a listbox of PersonViewModel.
  2. When the user selects a PersonViewModel from the listbox, I want to Navigate to a details (Details.xaml) page of the selected PersonViewModel.
  3. The details page does some extra heavy lifting that I only want done once the user navigates to the page. (I don't want too much stuff loaded in each PersonViewModel of the master listbox)

So how do you guys handle master/detail scenarios with navigation while maintaining "blendability"?

I've been turing in circles for the past week. there seems to be no clean solution for something that should be quite common?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月亮是我掰弯的 2024-09-08 17:41:01

找到了一个我非常满意的解决方案。当 IsInDesignTool 为 true 时,我会调用命令来伪造用户交互(例如:PlayCommand),因此当我看到混合中的设计区域时,就好像用户已经触发了该命令。

public class ViewModelLocator
{
    public ViewModelLocator()
    {
        if (DesignerProperties.IsInDesignTool)
        {
            MainViewModel = new MainViewModel(new GameDataDummy());

            //Fake user interactions
            MainViewModel.PlayCommand.Execute(null);
        }
        else
        {
            MainViewModel = new MainViewModel(new GameData());
        }
    }

    public MainViewModel MainViewModel { get; private set; }

}

Found a solution that i'm pretty happy with. When IsInDesignTool is true, I call commands to fake user interactions (Ex: PlayCommand) so when I see the Design area in blend, it's as if the user already fired the command.

public class ViewModelLocator
{
    public ViewModelLocator()
    {
        if (DesignerProperties.IsInDesignTool)
        {
            MainViewModel = new MainViewModel(new GameDataDummy());

            //Fake user interactions
            MainViewModel.PlayCommand.Execute(null);
        }
        else
        {
            MainViewModel = new MainViewModel(new GameData());
        }
    }

    public MainViewModel MainViewModel { get; private set; }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文