WPF圆角背景出现渗透问题

8
我正在尝试进入WPF领域 - 我有一个简单的表单,其中定义了一个弹出框用于内联帮助。我使用了圆角,但是某些原因导致黑色背景在角落处渗透出来。我不明白哪个元素导致了这个问题。

alt text http://www.awbrey.net/rounded.jpg

我认为这是一些非常显而易见的东西,但我却没有看到。以下是我使用的XAML代码:
<Window x:Class="Consent.Client.SubjectNumberEntry"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" FontSize="24"
    Title="SubjectNumberEntry" WindowStyle="None" WindowState="Maximized"
        xmlns:h="clr-namespace:Consent.Client" KeyDown="windowOuter_KeyDown" Background="White" Name="windowOuter" AllowsTransparency="true" Loaded="Window_Loaded">

    <StackPanel Height="400" DockPanel.Dock="Top" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10">
        <StackPanel Height="60" Orientation="Horizontal" VerticalAlignment="Center">
            <TextBox Name="txtSubjectNumber" Margin="10" Width="400" KeyDown="txtSubjectNumber_KeyDown" h:HelpProvider.HelpString="Enter the subject identifier, or scan their wristband">
                <TextBox.ToolTip>This is a textbox</TextBox.ToolTip>
            </TextBox>
            <Button Name="btnEnter" Margin="10" Width="100" Click="btnEnter_Click">Enter</Button>
            <Button Width="50" Name="btnHelp" Margin="10" Click="btnHelp_Click">?</Button>
            <Button Width="50" Name="btnExit" Margin="10" Click="btnExit_Click">Exit</Button>


        </StackPanel>
        <Label Name="lblValue" Margin="10"></Label>


        <Popup Placement="Bottom" HorizontalAlignment="Center" VerticalOffset="10" MouseDown="popHelp_MouseDown" PopupAnimation="Fade" Name="popHelp" PlacementTarget="{Binding ElementName=txtSubjectNumber}">
            <Border Padding="10" Margin="10" BorderBrush="CornflowerBlue" BorderThickness="1" CornerRadius="10" Background="CornflowerBlue">
                <TextBlock FontSize="12" Background="CornflowerBlue">This is the content of the help box.</TextBlock>
            </Border>
        </Popup>

    </StackPanel>


</Window>
2个回答

27

我认为问题是由弹出窗口引起的。尝试在弹出窗口上将AllowsTransparency设置为True。

Popup.AllowsTransparency

当设置为False时,任何透明的颜色都会与黑色“合并”。


1
您还可以将弹出窗口包装在带有圆角的边框中。如果您无法更改弹出窗口的AllowsTransparency,这将非常有用。
类似于这样的效果:
<Border CornerRadius="10">
    <Popup Placement="Bottom" HorizontalAlignment="Center" VerticalOffset="10" MouseDown="popHelp_MouseDown" PopupAnimation="Fade" Name="popHelp" PlacementTarget="{Binding ElementName=txtSubjectNumber}">
        <Border Padding="10" Margin="10" BorderBrush="CornflowerBlue" BorderThickness="1" CornerRadius="10" Background="CornflowerBlue">
            <TextBlock FontSize="12" Background="CornflowerBlue">This is the content of the help box.</TextBlock>
        </Border>
    </Popup>
</Border>

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