Darth Sucuk
Darth Sucuk

Reputation: 254

how to set position of WPF in c#

I wrote a program in WPF via using Visual Studio and my program works perfectly.When I publish it, it seems like the image below on internet explorer.I just want to see my app on top.

This is my current view This is my current view This is what I want This is what I want

Page1.XML

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="Page1">
<Grid>
    <StackPanel Margin="0,0,0,0" Name="stackPanel" 

       HorizontalAlignment="Left" VerticalAlignment="Top" />
</Grid>

Page1.xaml.cs

using System.Windows.Controls;
using System.Windows.Forms.Integration;
using BenzinTakip;

namespace WPFHost
{
    /// <summary>
    /// Interaction logic for Page1.xaml
    /// </summary>
    public partial class Page1 : Page
    {
        private readonly Form1 mainForm = new Form1();

        public Page1()
        {
            InitializeComponent();

            //Create a Windows Forms Host to host a form
            WindowsFormsHost windowsFormsHost = new WindowsFormsHost();

            mainForm.TopLevel = false;

            windowsFormsHost.Child = mainForm;

            stackPanel.Children.Add(windowsFormsHost);
        }
    }
}

Upvotes: 1

Views: 940

Answers (3)

Nuisance
Nuisance

Reputation: 455

It's because of your resolution you have to change your form's dimensions and it will fit.

Upvotes: 2

Kelly
Kelly

Reputation: 7183

Not sure exactly what your asking.

If you want your window to be above all other windows on the OS you can use the IsTopMost=true parameter.

If you want one element on your window to be shown above something else this is the Z-Order. In WPF the Z-Order is defined by the order the elements appear in your XAML. For instance if you create a button, then an image the image would be placed above the button, because the image is defined further down in the XAML.

Upvotes: 0

Lehlohonolo
Lehlohonolo

Reputation: 126

Try adding the code below in your <StackPanel> tag on the Page1.xml side of your code.

<StackPanel.Resources>
     <Style x:Key="StackPanelMargining" TargetType="Control">
        <Setter Property="Margin" Value="0,0,0,0"/>
     </Style>
     <Style BasedOn="{StaticResource StackPanelMargining}" TargetType="Your Target Element"/>
</StackPanel.Resources>

Upvotes: 0

Related Questions