using System;using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
"SampleUserControl.xaml.cs"
namespace SampleWpfUserControlLibrary
{
/// <summary>
/// Interaction logic for SampleUserControl.xaml
/// </summary>
public partial class SampleUserControl
{
private IApplicationHostWindow _hostWindow;
public SampleUserControl()
{
InitializeComponent();
}
[Obsolete("This constructor should not be used",false)]
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;
}
}
}
"IApplicationHostWindow.cs"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SampleWpfUserControlLibrary
{
public interface IApplicationHostWindow
{
void OpenDocument();
void Exit();
}
}
What I did as off now is I added the WPF to VB.Net. As I run the program, an error occurs being null of _hostWindow.
http://i46.tinypic.com/mrpxi.png
on the line
_hostwindow.OpenDocument();
says "Object reference not set to an instance of an object"
It seems to work fine when I run the WPF only
http://i45.tinypic.com/oppylf.png