如何使用WPF页面之类的页面?

发布于 2025-02-02 13:45:23 字数 68 浏览 2 评论 0原文

在WPF中,我们有一个page类,该类允许我们在单个窗口中使用多页接口。如何在阿瓦洛尼亚做?

In WPF, we have a Page class that allows us to use a multi-page interface in a single window. How to do it in Avalonia?

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

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

发布评论

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

评论(1

孤星 2025-02-09 13:45:23

您所描述的通常用tabControl来解决。

每个选项卡可以具有TabViewModel派生的类实例,以绑定到其数据上下文。

TabAViewModel : TabViewModel
{
}

TabBViewModel : TabViewModel
{
}

然后,这些可以拥有自己的视图*。axaml文件... tabaview.axaml& tabbview.axaml在此实例中。它们可以包含任何任意UI。完整的内容屏幕或PATH的屏幕。

<UserControl>
...
</UserControl>

然后,您可以将tabControl绑定的收集集合在一起,因此在类似于mainviewModel.cs的东西

MainViewModel : MyBaseViewModel
{
   public ObservableCollection<TabViewModel> MyTabs { get; ... }
}

上然后看起来像这样。

<Window>
    <TabControl Items={Binding MyTabs}>
      <TabControl.DataTemplates>
          <TabAView />
      </TabControl.DataTemplates>
    </TabControl>
</Window>

现在被警告。这是伪代码,但它解释了概念以及如何融合在一起。我在WPF和Avalonia中做到了这一点。

为什么要伪代码?

根据您使用的框架,它们将大大更改有关如何执行此操作的实现详细信息。

prism中,您需要实现regionAdaptor,在Avalonia中,您可能需要一个dataTemplatesElector来接线> ViewModels,在WPF中,这或多或少地算出了框。

无论哪种方式,每个概念在每个概念中都是有效的。

What you're describing is often solved with a TabControl.

Each tab can have a TabViewModel derived class instance to bind to as its data context.

TabAViewModel : TabViewModel
{
}

TabBViewModel : TabViewModel
{
}

These can then have their own views *.axaml files ... so TabAView.axaml & TabBView.axaml in this instance. They can contain any arbitrary UI. Full screens of stuff or as little as a Path.

<UserControl>
...
</UserControl>

You can then have a collection of those that the TabControl binds too, so on something akin to a MainViewModel.cs ...

MainViewModel : MyBaseViewModel
{
   public ObservableCollection<TabViewModel> MyTabs { get; ... }
}

MainView.axal would then look like this.

<Window>
    <TabControl Items={Binding MyTabs}>
      <TabControl.DataTemplates>
          <TabAView />
      </TabControl.DataTemplates>
    </TabControl>
</Window>

Now be warned. This is pseudocode, but it explains the concepts and how things can hang together. I've done this in WPF and Avalonia.

Why Pseudocode?

Depending on what frameworks you are using they would drastically change the implementation details on how to do this.

In Prism you would need to implement a RegionAdaptor, in Avalonia you'd possibly need a DataTemplateSelector to wire up Views to ViewModels, in WPF this just more or less works out the box.

Either way, the concept is valid in each.

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