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

标签 c# wpf background-image

我想尝试制作一个登录屏幕,让 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/

相关文章:

css - 平铺背景中行的不同 x 背景位置

C# 调用 C++ dll 获取 EntryPointNotFoundException

c# - 多语言开发

c# - PCL 库可以与 ASP.NET MVC 一起运行吗?

ios - UISlider 中的静态统一背景图像?

css - 背景颜色/背景图像的底部在移动网站上被截断

c# - 如何在数据绑定(bind)转发器中创建条件内容

c# - 以非交互模式从 C# 执行 PowerShell

c# - 如果在 ListView 中未选择任何项目,如何禁用按钮

WPF TreeView : Where is the ExpandAll() method