VS 2008 可扩展性包 - 如何使用 ElementHost 附加 Wpf 数据项目

发布于 2024-10-04 19:29:42 字数 872 浏览 1 评论 0原文

我已经使用 Wpf 窗口、Sql 数据和 ElementHost 创建了一个包 - 非常简单,没有互操作,只是代码。现在我需要扩展并希望使用 Wpf 数据项目作为我的 ElementHost.Child。我添加了一个项目引用,并在 ToolWindow.cs 中使用了这行代码:

 elementHost.Child = WpfProject.Window1;

包运行并且 ToolWindow 打开并显示一个空白的 Wpf 框架。调试告诉我,我获得了 UI 元素引用,甚至 ToolWindow.cs 的数据,但它没有进入页面。我知道我缺少某种绑定语法,但在网上进行了大量搜索并没有揭示其中的魔力。我是否需要运行该项目,或者执行一些互操作技巧?能够完成这项工作真的很棒,因为如果我让它成功的话,我将能够重用主要的工作。 干杯,丹尼,

这是我放入 ToolWindow 类中的代码:

     private ElementHost elementHost;
     protected override void Initialize()
    {           
       base.Initialize();
        elementHost = new ElementHost();
        WpfDataTest.Window1 cv = new Window1(); 
        cv.Content = cv;
        elementHost.Child = cv;
    }
    override public IWin32Window Window
    {
        get
        {
            return (IWin32Window)elementHost;
        }
    }

I have already created a package using a Wpf window, Sql data and ElementHost- Pretty easy, no interop, just code. Now I need to expand and hopefully use a Wpf data project as my ElementHost.Child. I added a project reference and used this line of code in the ToolWindow.cs:

 elementHost.Child = WpfProject.Window1;

The package runs and the ToolWindow opens with a blank Wpf Frame. Debugging tells me that I got the UI element references and even the data to the ToolWindow.cs, but it is not making it to the page. I know I am missing some sort of binding syntax, but the big search on the net did not reveal the magic. Do I need to Run the project, or do some interop tricks? It will really be great to make this work as I will be able to reuse major work if I get this to fly.
Cheers, Danny

here is the code that I put into the ToolWindow class:

     private ElementHost elementHost;
     protected override void Initialize()
    {           
       base.Initialize();
        elementHost = new ElementHost();
        WpfDataTest.Window1 cv = new Window1(); 
        cv.Content = cv;
        elementHost.Child = cv;
    }
    override public IWin32Window Window
    {
        get
        {
            return (IWin32Window)elementHost;
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小红帽 2024-10-11 19:29:42

答案如下——
WpfDataTest.Window1 是 WPF Window 派生类。我只是将其更改为 WPFData 项目中的顶级 UserControl 并且它可以工作。作为额外说明,它需要是顶级控件(例如 Items Control、UserControl 或 Grid)才能工作。这个答案归功于 Ryan Molden。

Here is the answer-
WpfDataTest.Window1 was a WPF Window derived class. I simply changed it to a top level UserControl in my WPFData project and it works. As an extra note it needs to be top level controls such as Items Control, UserControl, or Grid to work. Credit for this answer goes to Ryan Molden.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文