创作者更新
XAML
您需要使用放置在应用程序背景上的组件,比方说RelativePanel
<RelativePanel Grid.Column="0" Grid.ColumnSpan="2" MinWidth="40" x:Name="MainGrid" SizeChanged="Page_SizeChanged"/>
<RelativePanel Grid.Column="0" Width="{Binding ElementName=MainGrid,Path=Width}" Background="#28000000"/>
<Grid>
<!--Having content here, for example textblock and so on-->
</Grid>
第二RelativePanel
用于设置模糊上方的阴影颜色。
.CS
然后您可以使用以下代码:
private void applyAcrylicAccent(Panel panel)
{
_compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
_hostSprite = _compositor.CreateSpriteVisual();
_hostSprite.Size = new Vector2((float) panel.ActualWidth, (float) panel.ActualHeight);
ElementCompositionPreview.SetElementChildVisual(panel, _hostSprite);
_hostSprite.Brush = _compositor.CreateHostBackdropBrush();
}
Compositor _compositor;
SpriteVisual _hostSprite;
并调用它applyAcrylicAccent(MainGrid);
您还需要处理 SizeChanged 事件:
private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (_hostSprite != null)
_hostSprite.Size = e.NewSize.ToVector2();
}
当然,您需要使用 Creator Update 才能运行此命令,CreateHostBackdropBrush() 无法在移动设备或平板电脑模式下运行。
另外,请考虑您使用丙烯酸颜色设置的面板或网格将无法显示任何控件(据我测试过)。因此,您需要使用相关面板,而无需对其进行任何控制。
透明标题栏
可以使用以下代码设置标题栏的透明度
ApplicationViewTitleBar formattableTitleBar = ApplicationView.GetForCurrentView().TitleBar;
formattableTitleBar.ButtonBackgroundColor = Colors.Transparent;
CoreApplicationViewTitleBar coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
coreTitleBar.ExtendViewIntoTitleBar = true;
Here a example of what the above code generate (with some other things added too.)
秋季更新 10.0.16190 及更高版本
正如 Justin XL 在下面的答案中提到的,从 Build 16190 及更高版本开始,开发人员可以访问位于以下位置的不同丙烯酸画笔:Windows.UI.Xaml.Media
(亚克力API https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.media.acrylicbrush)以及 Microsoft 的指南:亚克力材料指南 https://learn.microsoft.com/en-us/windows/uwp/style/acrylic