I am building a WinForms application and am trying to include a WPF app within it. The WPF in question is a log viewer written by HighCore and can be found here: Implementing a log viewer with WPF.
I followed this tutorial on how to get everything set up. One thing to note is that, when I expand the options for the ElementHost in VS, it does not display the log viewer in the "Select Hosted Content" dropdown. The log viewer is in my project however (I created it through the Project menu), so I ended up going with this little bit of code:
public MainForm()
{
InitializeComponent();
logViewer tslv = new logViewer();
elementHost.Child = tslv;
this.Controls.Add(elementHost1);
elementHost.BringToFront();
}
I added BringToFront()
because I didn't see the WPF when I ran the code for the first time. Now, this is what happens:
However, what I have in my VS designer looks like this:
The ElementHost is within a SplitContainer which itself is within a Panel (that is what I have selected in the VS designer image).
The WPF does not feel the need to be bound by the dimensions or position of the ElementHost (maybe it's rebelling). For example, if I set the Dock property of the ElementHost to Fill, the WPF fills the entire application window rather than just the space in the ElementHost.
Aside from placing the WPF in its own window or porting the WinForms app to WPF, does anyone have any suggestions?
LogEntries
from my main WinForm (and not enough rep to comment on your answer! grr). For example, I can't get a hold ofLogEntries
(I've also looked at this). Perhaps you can explain or edit your answer? Or maybe it should be a question of its own. – valsidalvLogEntries
is a simple ObservableCollection, you should keep that separate from the WPF UI (probably as part of a ViewModel) and manipulate the ViewModel from the outside (winforms or otherwise). You almost never need to manipulate the WPF UI in procedural code. – Federico Berasategui