WPF Popup has black border instead of transparent
I programmatically create a popup for an element in a WPF window and can't get rid of the black border:
var p = new Popup {
PlacementTarget = target,
IsOpen = true,
StaysOpen = false,
AllowsTransparency = true
};
// Add the popup content
p.Child = new Views.MapLocationInformation {DataContext = context};
The custom control MapLocationInformation
is defined in XAML as follows:
<UserControl ...
mc:Ignorable="d"
Background="Transparent"
d:DesignHeight="65" d:DesignWidth="401">
<Border BorderThickness="1"
CornerRadius="5"
BorderBrush="{StaticResource ExpanderHeaderBorderGradient}"
Background="White"
Margin="0 0 8 8">
<Stackpanel> ... </Stackpanel>
</Border>
</UserControl>
I can't seem to find a combination of border, background fill, and transparency setting that will make the black area transparent. Any idea?
Your Popup allows transparency, but does not use a transparent background. Change to:
var p = new Popup {
PlacementTarget = target,
IsOpen = true,
StaysOpen = false,
AllowsTransparency = true,
Background = Brushes.Transparent
};
This should do the trick. Also, the reason the black bit is wider on the right and bottom is due Margin
to yours Border
, which is actually useless. I also suggest that you remove this.
This is caused by the property Background
MapLocationInformation
. Just set to Background
UserControl
null and AllowsTransparency
to True
to fix it, e.g .:
<UserControl ...
mc:Ignorable="d"
Background="{x:Null}"
AllowsTransparency="True"
I faced the same problem. The problem is that when the Popup property IsOpen
is set True
too early, transparency does not work as expected.
My solution was to move the parameter IsOpen
to true from the project to the Loaded
popup event .
myPopup.Loaded += (sender, args) => { myPopup.IsOpen = true; };