0

我在 Microsoft/Windows 商店中有一个 UWP 应用程序,我想添加一个弹出窗口。单击按钮时会出现此弹出窗口。弹出窗口是否有可能具有流畅的设计系统(透明背景)?

4

1 回答 1

0

是的。以下示例取自 Microsoft 的 Popup 类文档,此处为:

代码隐藏:

// Handles the Click event on the Button inside the Popup control and 
// closes the Popup. 
private void ClosePopupClicked(object sender, RoutedEventArgs e)
{
    // if the Popup is open, then close it 
    if (StandardPopup.IsOpen) { StandardPopup.IsOpen = false; }
}

// Handles the Click event on the Button on the page and opens the Popup. 
private void ShowPopupOffsetClicked(object sender, RoutedEventArgs e)
{
    // open the Popup if it isn't open already 
    if (!StandardPopup.IsOpen) { StandardPopup.IsOpen = true; }
} 

XAML:

<Grid x:Name="Output" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1">
    <StackPanel>
        <Button Content="Show Popup (using Offset)" Click="ShowPopupOffsetClicked"/>
    </StackPanel>
    <Popup VerticalOffset="10" HorizontalOffset="200" x:Name="StandardPopup">
        <Border BorderBrush="{StaticResource ApplicationForegroundThemeBrush}" 
                Background="{StaticResource ApplicationPageBackgroundThemeBrush}"
                BorderThickness="2" Width="200" Height="200">
            <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
                <TextBlock Text="Simple Popup" FontSize="24.667" HorizontalAlignment="Center"/>
                <Button Content="Close" Click="ClosePopupClicked" HorizontalAlignment="Center"/>
            </StackPanel>
        </Border>
    </Popup>
</Grid>

通过简单地更改对象的Background依赖属性Border

Background="{StaticResource ApplicationPageBackgroundThemeBrush}" 

Background="{StaticResource NavigationViewExpandedPaneBackground}"

您的 Popup 将设置一个 Acrylic 背景(这是一个在 NavigationView 的模板中为其视觉状态之一定义的 Acrylic Brush 资源)。

或者,您可以随时创建自己的 Acrylic Brush 资源:

<Grid.Resources>
<AcrylicBrush x:Name="myacrylicbrush" BackgroundSource="HostBackdrop"
                          TintColor="#FF0000FF"
                          TintOpacity="0.4"
                          FallbackColor="#FF0000FF"/>
</Grid.Resources>

有了这个,您可以将 Border Background 属性设置为您的自定义资源,如下所示:

Background="{StaticResource myacrylicbrush}"

并调整设置以获得您所追求的外观。BackgroundSource 设置为 HostBackDrop,为了使用您的 Background Acrylic,Tint 覆盖层设置为一个相当透明的值,而 TintColor 设置为完全不透明的蓝色。

结果:

在此处输入图像描述

如果您想将Background属性定义Acrylic brush为任何控件,如果您的目标是具有 Falls Creator 更新的应用程序,我认为问题可能应该是相反的:我在哪里无法使用新发布的功能?

于 2018-01-04T20:02:08.227 回答