Error after Adding WPF on VB.Net

k3nnt0ter0

Member
Joined
Sep 6, 2012
Messages
7
Programming Experience
Beginner
I embedded the WPF to vb.net and I got some error.
1. There's still a green underline on line
C#:
Me.SampleUserControl1 = New SampleWpfUserControlLibrary.SampleUserControl()
but that's nothing I guess since the underline was green.
2. My very problem is on the line
C#:
_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 :
C#:
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;


            I****TestVisible = 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;
        }
    }
}
 

k3nnt0ter0

Member
Joined
Sep 6, 2012
Messages
7
Programming Experience
Beginner
IApplicationHostWindow interface is not from WPF or anywhere in .Net framework libraries, it has probably something to do with your library.
Any clue what to do about that something in my library?

It works fine if I run the WPF only. I get error when I add it on the VB Project. .
 
Last edited:

k3nnt0ter0

Member
Joined
Sep 6, 2012
Messages
7
Programming Experience
Beginner
Anyone? Here are some related code
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace SampleWpfUserControlLibrary
{
    public interface IApplicationHostWindow
    {
        void OpenDocument();
        void Exit();
    }
}


It is from the C++ File

C#:
[COLOR=blue][FONT=Consolas]using[/FONT][/COLOR][COLOR=blue][FONT=Consolas]namespace[/FONT][/COLOR][COLOR=black][FONT=Consolas] SampleWpfUserControlLibrary;[/FONT][/COLOR]
 [COLOR=blue]ref[/COLOR] [COLOR=blue]class[/COLOR] ApplicationHostWrapper : IApplicationHostWindow
{
[COLOR=blue]public[/COLOR]:    ApplicationHostWrapper(CMainFrame * pMainFrame)    
{        _pMainFrame = pMainFrame;    
}       
[COLOR=blue]virtual[/COLOR] [COLOR=blue]void[/COLOR] __clrcall Exit() [COLOR=blue]sealed[/COLOR]   
 {       
 _pMainFrame->SendMessage(WM_CLOSE);    
}     
[COLOR=blue]virtual[/COLOR] [COLOR=blue]void[/COLOR] __clrcall OpenDocument() [COLOR=blue]sealed[/COLOR]   
 {        _pMainFrame->OpenDocument();    
} [COLOR=blue]private[/COLOR]:    CMainFrame * _pMainFrame;
};
 

JohnH

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
895
Location
Norway
Programming Experience
10+

k3nnt0ter0

Member
Joined
Sep 6, 2012
Messages
7
Programming Experience
Beginner
Is that so?
But according to the goal stated on that link
1. Create a reusable component (ActiveX) in C++ using MFC which could later be embedded into a .NET-base application;
I guess it will be reusable. .
 

k3nnt0ter0

Member
Joined
Sep 6, 2012
Messages
7
Programming Experience
Beginner
I missed that one. Anyway, can I at least make it at the top most of the form? I mean It will not be brought back if I pressed somehow click or did something on the form behind it?
 
Top Bottom