Error after Adding WPF on VB.Net
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Thread: Error after Adding WPF on VB.Net

  1. #1
    Join Date
    Aug 2012
    Posts
    16

    Error after Adding WPF on VB.Net

    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
    Last edited by k3nnt0ter0; October 10th, 2012 at 05:55 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center