弹出窗口和窗口允许透明度

时间:2017-06-20 09:15:14

标签: wpf popup .net-4.5

只要我在一个窗口中将AllowsTransparency设置为true并关闭此窗口前面的弹出窗口,窗口就不会重新绘制,弹出窗口仍显示在窗口顶部。

如果此窗口失去焦点或者如果我输入" alt"键盘的键,窗口被重绘并正确显示。

更清楚:

没有AllowTransparency

显示弹出窗口:

Popup shown

隐藏弹出窗口:

Popup hidden

使用AllowTransparency

显示弹出窗口:

Popup shown

隐藏弹出窗口:

Popup hidden

XAML:

<Window x:Class="Tests.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="300" Width="1000"
        WindowStyle="None"
        AllowsTransparency="True">
    <Grid>
        <Rectangle Width="1000" Height="300" Fill="Red"></Rectangle>
        <CheckBox x:Name="PopupCheckBox">
            <TextBlock Text="Show popup"/>
        </CheckBox>
        <Popup IsOpen="{Binding ElementName=PopupCheckBox, Path=IsChecked}" Placement="Center">
            <Rectangle Width="500" Height="500" Fill="Green" />
        </Popup>
    </Grid>
</Window>

我想知道这种行为的原因是什么以及如何修复/绕过它。

谢谢。

修改

我试图在弹出窗口的Closed事件的处理程序中调用InvalidateVisual,但它没有改变行为:

public MainWindow()
{
    InitializeComponent();
    PopupTest.Closed += PopupTest_Closed;
}

void PopupTest_Closed(object sender, EventArgs e)
{
    InvalidateVisual();
}

编辑2

好的,因此看起来图形卡驱动程序是导致此行为的原因。我将其更新为最新版本,虽然仍然显示了一个工件,但它的行为却不同(弹出窗口的区域要小得多)。

关闭此帖子。谢谢大家。

2 个答案:

答案 0 :(得分:1)

如问题的最新编辑中所述,该工件是由过时的图形卡驱动程序引起的。

答案 1 :(得分:0)

我无法告诉您原因,但要解决此问题,请在关闭弹出窗口时使用窗口上的InvalidateVisual方法。

window.InvalidateVisual();