VS 2008 Extensibility Package- How to attach Wpf Data project using 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 t开发者_如何学编程o 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;
}
}
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.
精彩评论