【问题标题】:How to combine multiple xaml pages in one xaml page?如何在一个 xaml 页面中合并多个 xaml 页面?
【发布时间】:2016-10-03 08:41:26
【问题描述】:

对于 xaml 页面的 wpf 中的主布局和子布局有什么想法吗? 我有一个 xaml 文件,我想在两个不同的 Xaml 文件中使用它,这些文件具有不同的数据但具有相同的 UI。 我不想两次创建相同的设计,我只想在两个地方都只有一个 xaml 页面。

【问题讨论】:

  • 您可以选择构建一个 UserControl 并多次使用它,每次都有自己的视图模型。这是一个选择吗?
  • 你检查过答案了吗?

标签: wpf xaml uwp-xaml


【解决方案1】:

使用 ContentControl 和不同的 ContentTemplate。将这些ContentTemplate 定义为Resource。在ContentTemplateDataTemplate 中指定DataType。在不同的地方,只需使用Binding 设置您的ContentControl 的适当Content。这个Content 可以是任何类型的任何属性。

例如;

<ContentControl Content="{Binding View1}" />

<ContentControl Content="{Binding View2}" />

Beauty is DataTemplateContentControl 自动拾取。

【讨论】:

  • 感谢 Anjum 的解决方案,我正在尝试解决和理解这些概念。我给你一个,只要我达到要求。或者我会想出一些新的机会。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-07-19
  • 1970-01-01
  • 1970-01-01
  • 2018-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多