C# 如何设置WPF在c中的位置#
我使用Visual Studio在WPF中编写了一个程序,我的程序运行得非常好。当我发布它时,它看起来就像internet explorer上的下图。我只想在上面看到我的应用程序 这是我目前的看法 这就是我想要的 Page1.XMLC# 如何设置WPF在c中的位置#,c#,wpf,xbap,C#,Wpf,Xbap,我使用Visual Studio在WPF中编写了一个程序,我的程序运行得非常好。当我发布它时,它看起来就像internet explorer上的下图。我只想在上面看到我的应用程序 这是我目前的看法 这就是我想要的 Page1.XML xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml" Title=“第1页
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml"
Title=“第1页”>
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);
}
}
}
使用System.Windows.Controls;
使用System.Windows.Forms.Integration;
使用BenzinTakip;
命名空间WPFHost
{
///
///Page1.xaml的交互逻辑
///
公共部分类第1页:第页
{
private readonly Form1 mainForm=new Form1();
公共页1()
{
初始化组件();
//创建Windows窗体宿主以宿主窗体
WindowsFormsHost WindowsFormsHost=新WindowsFormsHost();
mainForm.TopLevel=false;
windowsFormsHost.Child=mainForm;
stackPanel.Children.Add(windowsFormsHost);
}
}
}
尝试在代码的Page1.xml
一侧的
标记中添加以下代码
<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>
不确定您的要求是什么 如果希望您的窗口高于操作系统上的所有其他窗口,可以使用IsTopMost=true参数
如果希望窗口中的一个元素显示在其他元素的上方,这就是Z顺序。在WPF中,Z顺序由元素在XAML中的显示顺序定义。例如,如果您创建了一个按钮,那么图像将被放置在按钮上方,因为该图像在XAML中定义得更深 这是因为您的分辨率,您必须更改表单的尺寸,它将适合您。您的Form1类是如何定义的?您可以向我们展示其中显示的网页的代码吗?我已经完成了,它修复了我的问题,谢谢您的回答如果它修复了,请写在这里,因为您的问题似乎没有答案
<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>