首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >用于导航wpf的内容控件或停靠面板

用于导航wpf的内容控件或停靠面板
EN

Stack Overflow用户
提问于 2018-06-07 03:40:32
回答 1查看 486关注 0票数 0

我使用Contentcontrol来显示程序的用户控件,现在我在搜索后关闭用户控件出现了问题,我发现了一个在DockPanel上加载用户控件的例子

现在我的问题是:

  1. 这两个控件有什么区别?(Dockpanel vs ContentControl)
  2. Is是否可以使用此控件(Dockpanel)而不是内容控件来显示应用程序用户控件?新控件是否有类似的代码? UIPanel.Children.Add(ChildWindow);

ucChild=ContentControl)

  • Is ucChild();ChildWindow.ParentControl = this.UIPanel;UIPanel.Children.Clear();ucChild
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-07 04:04:47

对于像WinForms这样编写

的人来说,WPF标准免责声明:优先;像这样直接操作UI是一个坏主意。您应该修改视图模型并允许绑定系统更新UI。使用MVVM模式;WPF将为您工作,而不是对您不利

回答你的实际问题:

  1. 一切。我的意思是,它们都继承自FrameworkElement,但就共性而言仅此而已。

代码语言:javascript
复制
- A `DockPanel` is as the name suggests, a `Panel`. That is; it controls the layout and sizing of one or more child elements. Specifically, `DockPanel` is good at situations like the following: you want an element to use up a full column of width, then another span the top (except for the previous element) and have the last element fill the remaining space.
- A `ContentControl` is basically a placeholder, its purpose is to expose a settable (and most importantly, bindable) `Content` property that you can stuff another control into. Even better; you can put an actual _object_ there and use a `DataTemplate` to control the display (this approach would conform to MVVM).

  1. 你不能真的用一个替换另一个,请参见上面的
  2. No。ContentControl不是Panel,因此没有Children属性。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50728311

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档