P N*_*P N 52 wpf user-interface popup
我正在使用WPF Popup控件,它将背景显示为黑色.我把StackPanel放在它里面,背景="透明",但这没有帮助.
<Popup PlacementTarget="{Binding ElementName=parentStackPanel}" Placement="Center"
IsOpen="False" Name="m_popWaitNotifier" PopupAnimation="None"
AllowsTransparency="False">
<StackPanel Orientation="Vertical" Background="Transparent">
<uc:CircularProgressBar x:Name="CB" StartupDelay="0"
RotationsPerMinute="20"
Height="25" Foreground="White"
Margin="12"/>
</StackPanel>
</Popup>
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我如何使Popup背景透明(或任何颜色)?
Sve*_*lov 77
您需要将AllowsTransparency="True"Popup Property 设置为True
这是一个例子:
<Grid>
<StackPanel>
<Button Click="Button_Click" Width="100" Height="20" Content="Click" />
<Popup x:Name="popup" Width="100" Height="100" AllowsTransparency="True">
<Grid Background="Transparent">
<TextBlock Text="Some Text" />
</Grid>
</Popup>
</StackPanel>
</Grid>
Run Code Online (Sandbox Code Playgroud)
和点击处理程序
private void Button_Click(object sender, RoutedEventArgs e)
{
popup.Visibility = System.Windows.Visibility.Visible;
popup.IsOpen = true;
}
Run Code Online (Sandbox Code Playgroud)
Ric*_*key 14
a Popup或a的基色Window是黑色.你很少看到它 Window因为Window有一个Background属性而且它默认为纯色,但如果设置Window.Background为Transparent它也会是黑色.但是Popup没有Background财产,所以,原谅双关语,这个问题"弹出".
如果您希望Popup透明,则需要进行设置AllowsTransparency="True".但是,如果你想要的Popup是纯色,最简单的方法是使的孩子Popup一个Panel支持Background属性,并设置属性为你想要的颜色,然后设置的孩子Panel到您所希望的内容该Popup摆在首位.我建议Grid因为它不会影响你的布局Popup.它的唯一效果就是给你你想要的背景颜色.
Zen*_*eer 10
确保允许透明度设置为true,垂直和水平对齐居中,高度和宽度设置为"自动".
例如:
<Popup Name="popup1" Placement="Top" PlacementTarget="{Binding ElementName=button2}" AllowsTransparency="True" Height="Auto" Width="Auto" Panel.ZIndex="1" HorizontalOffset="-5" HorizontalAlignment="Center" VerticalAlignment="Center">
<StackPanel Height="92" HorizontalAlignment="Left" Margin="93,522,0,0" Name="stackPanelPop" VerticalAlignment="Top" Width="147">
</StackPanel>
</Popup>
Run Code Online (Sandbox Code Playgroud)