WPF Window 左上角不透明
WPF Window top left corner not being transparent
我有以下WPF无边框window:
<Window x:Class="MyAPP.WMainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib"
Height="620" Width="800"
WindowStyle="None"
AllowsTransparency="True"
ResizeMode="CanResizeWithGrip">
<Window.Resources>
<Style x:Key="WindowIconStyle"
TargetType="{x:Type Hyperlink}">
<Setter Property="FontFamily"
Value="Webdings" />
<Setter Property="FontSize"
Value="16" />
<Setter Property="Foreground"
Value="Black" />
<Setter Property="TextBlock.TextDecorations"
Value="{x:Null}" />
<Setter Property="Cursor"
Value="{x:Null}" />
<Style.Triggers>
<Trigger Property="IsMouseOver"
Value="True">
<Setter Property="Foreground"
Value="#ED5326" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Border BorderBrush="SkyBlue" BorderThickness="2" CornerRadius="20 0 0 0">
<DockPanel>
<Border x:Name="WindowTitleBar"
DockPanel.Dock="Top"
CornerRadius="20 0 0 0"
Background="LightBlue">
<StatusBar DockPanel.Dock="Top" Background="Transparent"
MouseDoubleClick="TriggerMaximize"
MouseMove="TriggerMoveWindow">
<StatusBarItem DockPanel.Dock="Right">
<TextBlock Margin="5"
VerticalAlignment="Center">
<Hyperlink Click="TriggerClose"
Style="{StaticResource WindowIconStyle}">r
</Hyperlink>
</TextBlock>
</StatusBarItem>
<StatusBarItem DockPanel.Dock="Right">
<TextBlock Margin="5"
VerticalAlignment="Center">
<Hyperlink Click="TriggerMaximize"
Style="{StaticResource WindowIconStyle}">2
</Hyperlink>
</TextBlock>
</StatusBarItem>
<StatusBarItem DockPanel.Dock="Right">
<TextBlock Margin="5"
VerticalAlignment="Center">
<Hyperlink Click="TriggerMinimize"
Style="{StaticResource WindowIconStyle}">0
</Hyperlink>
</TextBlock>
</StatusBarItem>
<StatusBarItem HorizontalAlignment="Center">
<TextBlock x:Name="WindowTitle" VerticalAlignment="Center"
Foreground="Black"
FontSize="16"/>
</StatusBarItem>
</StatusBar>
</Border>
<Grid>
<!-- Grid Stuff -->
</Grid>
</DockPanel>
</Border>
如上所示,我将边框作为主要 window 内容放置,以便应用自定义角半径“20 0 0 0”,也就是说,我将 window 圆角左上角不透明,见下图:
将 window 的背景设置为 Transparent
。
我有以下WPF无边框window:
<Window x:Class="MyAPP.WMainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib"
Height="620" Width="800"
WindowStyle="None"
AllowsTransparency="True"
ResizeMode="CanResizeWithGrip">
<Window.Resources>
<Style x:Key="WindowIconStyle"
TargetType="{x:Type Hyperlink}">
<Setter Property="FontFamily"
Value="Webdings" />
<Setter Property="FontSize"
Value="16" />
<Setter Property="Foreground"
Value="Black" />
<Setter Property="TextBlock.TextDecorations"
Value="{x:Null}" />
<Setter Property="Cursor"
Value="{x:Null}" />
<Style.Triggers>
<Trigger Property="IsMouseOver"
Value="True">
<Setter Property="Foreground"
Value="#ED5326" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Border BorderBrush="SkyBlue" BorderThickness="2" CornerRadius="20 0 0 0">
<DockPanel>
<Border x:Name="WindowTitleBar"
DockPanel.Dock="Top"
CornerRadius="20 0 0 0"
Background="LightBlue">
<StatusBar DockPanel.Dock="Top" Background="Transparent"
MouseDoubleClick="TriggerMaximize"
MouseMove="TriggerMoveWindow">
<StatusBarItem DockPanel.Dock="Right">
<TextBlock Margin="5"
VerticalAlignment="Center">
<Hyperlink Click="TriggerClose"
Style="{StaticResource WindowIconStyle}">r
</Hyperlink>
</TextBlock>
</StatusBarItem>
<StatusBarItem DockPanel.Dock="Right">
<TextBlock Margin="5"
VerticalAlignment="Center">
<Hyperlink Click="TriggerMaximize"
Style="{StaticResource WindowIconStyle}">2
</Hyperlink>
</TextBlock>
</StatusBarItem>
<StatusBarItem DockPanel.Dock="Right">
<TextBlock Margin="5"
VerticalAlignment="Center">
<Hyperlink Click="TriggerMinimize"
Style="{StaticResource WindowIconStyle}">0
</Hyperlink>
</TextBlock>
</StatusBarItem>
<StatusBarItem HorizontalAlignment="Center">
<TextBlock x:Name="WindowTitle" VerticalAlignment="Center"
Foreground="Black"
FontSize="16"/>
</StatusBarItem>
</StatusBar>
</Border>
<Grid>
<!-- Grid Stuff -->
</Grid>
</DockPanel>
</Border>
如上所示,我将边框作为主要 window 内容放置,以便应用自定义角半径“20 0 0 0”,也就是说,我将 window 圆角左上角不透明,见下图:
将 window 的背景设置为 Transparent
。