简体   繁体   English

在WPF中呈现一组控件的最佳实践?

[英]best practice for rendering a set of controls in WPF?

I'm creating a WPF application that is similar in layout to Microsoft Outlook, where you have some navigation buttons on the left and then a grid on the right hand side that displays content. 我正在创建一个布局类似于Microsoft Outlook的WPF应用程序,该应用程序的左侧是一些导航按钮,右侧是显示内容的网格。 I'd like this content area (which is just a Grid, split into a left side of specific Width, and then Width="*" for the right side) to change based on the selected item on the left side. 我希望此内容区域(只是一个Grid,分成特定Width的左侧,然后在Width =“ *”的右侧)根据左侧的所选项目进行更改。 It will render a different set of labels and buttons, etc when the item changes on the left side. 当项目在左侧更改时,它将呈现一组不同的标签和按钮等。 I was curious what would be considered the best way to render content on the right side of the form, specifically: 我很好奇什么是在表单右侧呈现内容的最佳方法,特别是:

  • Use a Canvas control, and place controls on it and "swap" Canvas controls out as the selected item changes? 使用Canvas控件,并在其上放置控件,然后随着所选项目的更改“交换” Canvas控件?
  • Create some sort of a User Control to swap out content in this area? 创建某种用户控件以交换该区域中的内容?

I realize this question is subjective, but I'm looking for feedback from more experienced developers on how they usually handle this kind of work. 我意识到这个问题是主观的,但是我正在寻找经验丰富的开发人员有关他们通常如何处理此类工作的反馈。

EDIT: The right hand side needs to render a specific UI for each selected item - in other words the UI on the right side is custom to the selected item on the left. 编辑:右侧需要为每个选定的项目渲染一个特定的UI-换句话说,右侧的UI是针对左侧的选定项目定制的。

What you're probably looking for here is a data template. 您可能在这里寻找的是数据模板。 If your right hand pane was a ContentControl , you can bind the content to the selected item on the left hand side. 如果您的右窗格是ContentControl ,则可以将内容绑定到左侧的所选项目。 Then, you can define data templates for each object type you have in your list on the left. 然后,您可以为左侧列表中的每种对象类型定义数据模板。

There's almost never need to use code to swap content around in WPF - that's what the DataTemplate behaviour is designed for. 在WPF中几乎不需要使用代码来交换内容-这就是DataTemplate行为的目的所在。

Could you use a TabControl with the tabs on the left side, and then style the tab header to look non-tab like? 您能否将TabControl放在左侧的标签页上,然后将标签页标题设置为非标签页样式? does it NEED to be a gridview with a split? 是否需要成为带有拆分的gridview?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM