在屏幕顶部显示WPF窗口

4

我正在开发一个WPF应用程序。 我需要像窗口任务栏一样在屏幕顶部显示一个窗口。

这是我的XAML代码:

<Window x:Class="testProject.Notification.TestWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:testProject.Notification"
        mc:Ignorable="d"
        Title="TestWindow" Height="80" Topmost="True" ResizeMode="NoResize" WindowStyle="None">
    <Grid Background="Blue"/>
</Window>

我需要一个类似下面这样的蓝色窗口(来自Mac OSX应用程序的截图):
enter image description here
1个回答

4
这将为您解决问题。
<Window x:Class="AtDTopCorner.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow"
        Height="35"
        WindowStyle="None"
        WindowStartupLocation="Manual"
        Top="5"
        Left="0"
        AllowsTransparency="True"
        Background="Blue"
        Width="{Binding Source={x:Static SystemParameters.FullPrimaryScreenWidth}}">
</Window>

谢谢Mohit,它很好用,我正在使用Top="0"而不是Top="5"。 - Abdul Manaf

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接