【发布时间】:2022-06-14 19:02:19
【问题描述】:
我创建了一个带圆角的无边框窗口,并为其添加了拖动事件和触发器。这是简单的代码:
<Window x:Class="DebugTest.MainWindow"
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:DebugTest"
mc:Ignorable="d" Height="200" Width="200"
AllowsTransparency="True" WindowStyle="None" Background="Transparent">
<Border x:Name="MainBorder" CornerRadius="15" Background="White" BorderBrush="Black" BorderThickness="1">
<Grid>
<Grid.Style>
<Style TargetType="Grid">
<Setter Property="Visibility" Value="Hidden" />
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=MainBorder,Path=IsMouseOver}" Value="True">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
<Button Content="x" HorizontalAlignment="Right" VerticalAlignment="Top"
Margin="5" Height="20" Width="20" Click="Button_Click"/>
</Grid>
</Border>
</Window>
public MainWindow()
{
InitializeComponent();
}
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
this.DragMove();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
但是当我运行exe文件时,点击窗口内的空白区域,按钮会出现很明显的闪烁情况。
奇怪的是,在 Visual Studio 中调试而不是双击文件时几乎不会出现这种情况,而 CornerRadius="0" 时也不会出现这种情况。
看起来它在点击时失去了鼠标悬停触发器,但我想不出任何好的方法来避免出现闪烁,并满足对圆角、的需求可拖动,并带有触发器。
【问题讨论】:
标签: wpf triggers border drag datatrigger