gpt4 book ai didi

c# - 如何将主窗口设置为不可见以在 WPF 中将图像显示为主窗口

转载 作者:行者123 更新时间:2023-11-30 12:26:08 25 4
gpt4 key购买 nike

我想尝试制作一个登录屏幕,让 children 只用他们的名字登录。我想使用图像作为登录屏幕而不是无聊的普通窗口。我唯一的问题是,每当我运行它时,图像周围仍然有一个框架,当我将主窗口设置为不可见时,它也会使其中的图像不可见。在下图中,您可以看到图像周围仍然有空白区域,即使它是透明的,它周围仍然有边框,我该如何摆脱它?

enter image description here

最佳答案

在您的窗口 xaml 中,将 WindowStyle 设置为 None,将 AllowsTransparency 设置为 true 并将 ResizeModeNoResize

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300"
ResizeMode="NoResize"
WindowStyle="None"
AllowsTransparency="True"
Background="{x:Null}">
<Grid>
...
</Grid>
</Window>

要移动无边框窗口,请使用此代码:

// In xaml
<Window ... MouseDown="Window_MouseDown">

// In code behind
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left) this.DragMove();
}

关于c# - 如何将主窗口设置为不可见以在 WPF 中将图像显示为主窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29730807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com