我对 WPF 很陌生,大约 4 小时新。我来自 ASP.net 和 Masterpages。
我正在查看可用于模板化窗口的控制模板示例,因此所有窗口看起来都一样。 其他帖子
有人可以指导我如何完成它的示例或从头到尾的示例代码吗?
第二部分:
ControlTemplate 是构建 WPF Windows 客户端应用程序的最佳方式吗?构建 WPF Windows 应用程序的最佳实践是什么。
谢谢
我对 WPF 很陌生,大约 4 小时新。我来自 ASP.net 和 Masterpages。
我正在查看可用于模板化窗口的控制模板示例,因此所有窗口看起来都一样。 其他帖子
有人可以指导我如何完成它的示例或从头到尾的示例代码吗?
第二部分:
ControlTemplate 是构建 WPF Windows 客户端应用程序的最佳方式吗?构建 WPF Windows 应用程序的最佳实践是什么。
谢谢
There really isn't a "best" way to architect WPF UIs. It all depends on the user experience your application will have.
If you want a very web-like experience you are probably better of using the pages constructs. Otherwise if you have windows, but want a common header, you may just want to make a control template for that. Maybe you need separate windows or maybe you just need to have a sub part of a grid panel change content depending on state... There are different ways to do things that are more or less suited to the type of client experience you want.
Although there are some best practices in relation to using MVC/MVVM design patterns, there isn't a "best" way to style and theme your controls. I don't consider WPF as friendly to newcomers as WinForms were, but at the same time it seems a lot more powerful in the long run. What might help you out are some basic levels of theming:
So you have to ask yourself when you say, "Make all windows look the same," do you mean changes are merely aesthetic/looks (styles), customizing how a collection of items are displayed (data/item templates) or altogether changing how a standard control looks and behaves or making sure the layout of controls on a page are the same across multiple windows/pages (control templates)?
Finally, the "end to end" of the other post you linked to is pretty simple. You take the control template there, and under your tag you simply add Template={StaticResource MyTemplateName} and the template is applied. This article on MSDN is a decent intro to control templating.