[英]Popup with Fluent Design System - UWP app
I have an UWP app in Microsoft/Windows Store, and I want to add a popup. 我在Microsoft / Windows应用商店中有一个UWP应用,我想添加一个弹出窗口。 This popup appears when I click a button.
当我单击一个按钮时,将显示此弹出窗口。 Is it possible for the popup to have the Fluent Design System (transparent background)?
弹出窗口是否可以具有Fluent设计系统(透明背景)?
Yes, it is. 是的。 The following example, is taken from their Microsoft's Popup class documentation, here :
以下示例取自其Microsoft的Popup类文档, 这里 :
Code-Behind: 代码隐藏:
// 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: 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>
By simply changing the Background
dependency property of the Border
object from: 通过简单地将
Border
对象的Background
依赖项属性更改为:
Background="{StaticResource ApplicationPageBackgroundThemeBrush}"
to 至
Background="{StaticResource NavigationViewExpandedPaneBackground}"
your Popup will be set with an Acrylic Background (this one is an Acrylic Brush resource in the template of the NavigationView defined for one of its visual state). 您的弹出窗口将使用丙烯酸背景设置(这是NavigationView模板中为其视觉状态之一定义的丙烯酸画笔资源)。
Or you can always create your own Acrylic Brush resource: 或者,您始终可以创建自己的丙烯酸画笔资源:
<Grid.Resources>
<AcrylicBrush x:Name="myacrylicbrush" BackgroundSource="HostBackdrop"
TintColor="#FF0000FF"
TintOpacity="0.4"
FallbackColor="#FF0000FF"/>
</Grid.Resources>
And with this you can set the Border Background property to your custom resource, like this: 这样,您可以将Border Background属性设置为自定义资源,如下所示:
Background="{StaticResource myacrylicbrush}"
And adjust the settings to get the look your are striving for. 并调整设置以获得您所追求的外观。 BackgroundSource is set to HostBackDrop, to use your Background Acrylic, the Tint overlay layer is set to a value which will be rather transparent, while the TintColor is set to full opaque blue.
BackgroundSource设置为HostBackDrop,以使用您的Background Acrylic,Tint叠加层设置为一个相当透明的值,而TintColor设置为全不透明蓝色。
Result: 结果:
If you want to define the Background
property as an Acrylic brush
of any control, if you are targeting an app with Falls Creator update, I think the question should probably be the other way around: Where am I not able to utilize the new released features? 如果您想将
Background
属性定义为任何控件的Acrylic brush
,如果您的目标是使用Falls Creator更新的应用程序,那么我想问题应该是相反的: 我在哪里无法利用新发布的功能?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.