如何设计 MVVM UserControl WPF 并将其托管到 Windows 窗体 ElementHost 中?
我有一些关于 WPF + MVVM + ElementHost 的问题。我尝试尽可能清楚地解释它。
我正在构建一个插件(VSTO 2010),这意味着我需要一个 ElementHost 来托管 WPF。
第一点意味着我的WPF只能是一个UserControl(WPF)
关于第1点和第2点;
可以构建一个具有像这样的 Popup(Children) 的 MVVM WPF(UserControl) 一个 哪个可以托管到 ElementHost 中?
我希望我的问题足够清楚!谢谢你的帮助。
i have a some questions about WPF + MVVM + ElementHost. I try to explain it so clear i can.
I'm building an addin(VSTO 2010) that's mean i need an ElementHost to hosted a WPF.
The first Point mean that my WPF can only be an UserControl (WPF)
Regarding Point 1 and 2 ;
It's possible to build an MVVM WPF(UserControl) having Popup(Children) like this One and which can be hosted into a ElementHost?
I hope my Question is enough clear! Thank u for helping.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你当然可以,但有一些问题。
我遇到了 WPF 控件在最初显示时无法绘制的问题,因此我通过在设置 Child 时调整宽度来解决这个问题。请参阅http://vstocontrib.codeplex.com/SourceControl/changeset/view/50a83624e34d#src%2fVSTOContrib.Core%2fWpf%2fWpfPanelHost.cs
接下来是您要构建的 MVVM 样式应用程序,围绕此问题的主要问题是围绕窗口/文档/自定义任务窗格的 VSTO 模型都不同,一个是基于打开工作簿(上下文),一种是窗口(视图),自定义任务窗格也是基于窗口(视图)。
MVVM 风格的应用程序更多地围绕当前上下文或当前打开的工作簿构建,我已经在 VSTO contrib 上工作了一段时间来解决这个问题,如果您需要功能区支持,它甚至在声明 RibbonXML 功能区时为您提供类似 MVVM 的绑定。
请访问 http://vstocontrib.codeplex.com 获取它,如果它确实对您有帮助,请告诉我。
最后是弹出窗口,没有什么能阻止你,但你会发现在 Office 2007 中,当你尝试第二次打开该窗口时,Office 可能会崩溃。以下代码将使您的 WPF 窗口体验更加流畅。
基本上,当您显示第一个窗口时,一切都很好,但 WPF 会启动一个应用程序,默认情况下该应用程序会在最后一个窗口关闭时退出。因此,当您的窗口关闭时,您尝试再次打开它,WPF 将崩溃:P
You sure can, there are a few gotcha's though.
I have had issues with my WPF control not drawing when initially displayed, so I worked around it by tweaking the width when the Child is set. See http://vstocontrib.codeplex.com/SourceControl/changeset/view/50a83624e34d#src%2fVSTOContrib.Core%2fWpf%2fWpfPanelHost.cs
Next is the MVVM style application you want to build, the main issue around this is the VSTO model around windows/documents/custom task panes are all different, one is based on the open workbook (context), one is windows (view) and custom task panes are also window based (view).
MVVM style apps are built more around the current context, or the current opened workbook, I have been working on VSTO contrib for a while now to solve this problem, it even gives you MVVM like bindings when declaring your RibbonXML ribbons if you need ribbon support.
Grab it at http://vstocontrib.codeplex.com and please let me know if it indeed helps you.
And finally the popup, there is nothing stopping you, but you will find in Office 2007 that when you try to open the window for a second time that Office will probably crash. The following code will make your WPF window experience a bit smoother.
Basically when you display the first window, all is good, but WPF will spin up a Application, which by default exits when the last window is closed. So when your window closes, then you try to open it again, WPF will blow up :P