弹出与流畅的设计系统 - UWP应用程序

时间:2018-01-04 19:20:01

标签: c# xaml uwp uwp-xaml fluent-design

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

1 个答案:

答案 0 :(得分:0)

是的,确实如此。以下示例取自其Microsoft的Popup类文档here

代码隐藏:

// 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}"

你的弹出窗口将设置一个丙烯酸背景(这个是为其视觉状态之一定义的NavigationView模板中的丙烯画笔资源)。

或者您始终可以创建自己的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,要使用背景丙烯酸,将Tint覆盖层设置为相当透明的值,而将TintColor设置为完全不透明的蓝色。

结果:

enter image description here

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

相关问题