4 Replies - 418 Views - Last Post: 21 September 2012 - 09:43 AM Rate Topic: -----

#1 k3nnt0ter0  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 181
  • Joined: 16-January 10

Removing the Window

Posted 21 September 2012 - 06:34 AM

I found this program and the WPF is embedded to a window. How can I show only the User Control itsel not embedded in a window. .
Here's the 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", true)]
        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;
        }
    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: Removing the Window

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9201
  • View blog
  • Posts: 34,573
  • Joined: 12-June 08

Re: Removing the Window

Posted 21 September 2012 - 06:48 AM

A user control requires to be in a form or another control. If you look at the form's properties you can turn off things like the close button, minimize, border, title bar, etc.. but you will still have the form there to display the user control.
Was This Post Helpful? 2
  • +
  • -

#3 k3nnt0ter0  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 181
  • Joined: 16-January 10

Re: Removing the Window

Posted 21 September 2012 - 09:27 AM

Can it be possible for Elementhost to handle a window like this?
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9201
  • View blog
  • Posts: 34,573
  • Joined: 12-June 08

Re: Removing the Window

Posted 21 September 2012 - 09:38 AM

New plan of attack - how about rearranging your project and see what happens when you try it!
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3574
  • View blog
  • Posts: 11,112
  • Joined: 05-May 12

Re: Removing the Window

Posted 21 September 2012 - 09:43 AM

The ElementHost is still a control. Like modi123_1 stated above a control needs to be in a form or another control. So you are back to the same basic problem.

It is possible to make a form without any borders or window adornments. This will give the effect that seem to be looking for which is WPF content hosted with WinForms, but without it looking like it is inside a form.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1