I embedded the WPF to vb.net and I got some error.
1. There's still a green underline on line
Code:
Me.SampleUserControl1 = New SampleWpfUserControlLibrary.SampleUserControl()
but that's nothing I guess since the underline was green.
2. My very problem is on the line
Code:
_hostWindow.OpenDocument();
says
Object reference not set to an instance of an object.
My guess is that, it was suppose to be hosted on a Window but in my project's case, it was hosted on an Elementhost
Here's the code :
Code:
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
namespace SampleWpfUserControlLibrary
{
/// <summary>
/// Interaction logic for SampleUserControl.xaml
/// </summary>
public partial class SampleUserControl
{
private IApplicationHostWindow _hostWindow;
[Obsolete("This constructor should not be used", false)]
public SampleUserControl()
{
InitializeComponent();
}
public SampleUserControl(IApplicationHostWindow applicationHostWindow)
{
_hostWindow = applicationHostWindow;
IsHitTestVisible = true;
InitializeComponent();
}
public double GetViewboxWidth()
{
return viewHost.ActualWidth;
}
public double GetViewboxHeight()
{
return viewHost.ActualHeight;
}
public void SetViewboxChild(UIElement child)
{
viewHost.Content = child;
}
public void ProcessLeftButtonDown(Point point)
{
var result = VisualTreeHelper.HitTest(this, point);
return;
}
protected override HitTestResult HitTestCore(PointHitTestParameters hitTestParameters)
{
return base.HitTestCore(hitTestParameters) ??
new PointHitTestResult(viewHost.Content as Visual ?? viewHost, hitTestParameters.HitPoint);
}
private void exitMenuItem_Click(object sender, RoutedEventArgs e)
{
_hostWindow.Exit();
}
private void newProjectMenuItem_Click(object sender, RoutedEventArgs e)
{
_hostWindow.OpenDocument();
}
private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
return;
}
private void UserControl_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
return;
}
}
}
It works fine when I run the WPF only. . But when I add it on the VB Project, error occurs