简体   繁体   中英

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 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);
        }
    }
}

这是因为您的分辨率,所以您必须更改表单的尺寸,并且它会适合您。

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM