我不知道如何更改在ContentDialog中打开的Popup元素的背景颜色。
<ContentDialog x:Name="MyDialog" MinWidth="600" Height="300" PrimaryButtonText="Close" IsPrimaryButtonEnabled="True" PrimaryButtonClick="UnicontaOrdersDialog_OnPrimaryButtonClick" SecondaryButtonText="Ok" SecondaryButtonClick="UnicontaOrdersDialog_OnSecondaryButtonClick" Background="White" Opened="MyDialog_Opened">
<Grid Background="White">
<Popup x:Name="MyPopup" Width="100" Height="100">
<Border Background="white" BorderBrush="Red" BorderThickness="1" Height="100" Width="100">
<TextBlock TextWrapping="Wrap">This is a popup. Background should be white</TextBlock>
</Border>
</Popup>
</Grid>
</ContentDialog>
答案 0 :(得分:0)
这是因为默认情况下,弹出窗口显示在XAML主窗口句柄中。您需要使其显示在其自己的(ContentDialog)顶级HWND中。为此,您需要使用18362中引入的ShouldConstrainToRootBounds属性。您需要将项目版本设置为18362。然后可以设置ShouldConstrainToRootBounds="False"
。
由于此新属性仅在18362起可用,因此建议您使用Conditional XAML来检测它是否在运行时可用,如下所示:
xmlns:Windows10version1903="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract, 8)"
<ContentDialog x:Name="MyDialog" Opened="MyDialog_Opened" Closed="MyDialog_Closed" PrimaryButtonText="Close" IsPrimaryButtonEnabled="True" SecondaryButtonText="Ok">
<Grid Background="White">
<Popup x:Name="MyPopup" Width="100" Height="100" Windows10version1903:ShouldConstrainToRootBounds="False">
<Border Background="White" BorderBrush="Red" BorderThickness="1" Width="100" Height="100">
<TextBlock TextWrapping="Wrap">This is a popup. Background should be white</TextBlock>
</Border>
</Popup>
</Grid>
</ContentDialog>