【问题标题】:How to replicate the window transparency effect found in the new DropBox UWP app如何复制新的 DropBox UWP 应用中的窗口透明效果
【发布时间】:2017-04-23 17:35:53
【问题描述】:

显然该效果是创作者更新中引入的一项功能。有没有人弄清楚用于实现这一目标的确切 API?更好的是一些示例代码,至少可以帮助我入门。

任何帮助将不胜感激。 :]

【问题讨论】:

  • 没有截图我只能假设你在谈论 Windows.UI.Composition.Compositor.CreateHostBackdropBrush() API。它将创建一个可以应用于 Visual 的画笔

标签: c# xaml uwp uwp-xaml


【解决方案1】:

您应该以 Windows Creators Update 为目标以使其正常工作

 using Windows.UI.Xaml.Hosting;

 //'this' is MainPage, but can be any UIElement
 var visual = ElementCompositionPreview.GetElementVisual(this);
 var brush = visual.Compositor.CreateHostBackdropBrush();
 var sprite = visual.Compositor.CreateSpriteVisual();
 sprite.Brush = brush;
 //Set to the size of the area, update on SizeChanged
 sprite.Size = new System.Numerics.Vector2(1000, 1000); 
 ElementCompositionPreview.SetElementChildVisual(this, sprite);

【讨论】:

  • 我可以在主页上使用它,但是主页(Pivot)上的内容现在被隐藏了。有什么办法解决吗?
  • @Shubhan,在最后一行而不是 this 使用页面上的一些元素作为背景。
  • @x2 同意我们可以使用任何元素作为背景,就我而言,我使用的是主页本身。大多数情况下首选使用网格
猜你喜欢
  • 1970-01-01
  • 2011-01-06
  • 1970-01-01
  • 1970-01-01
  • 2010-09-13
  • 1970-01-01
  • 2015-05-02
  • 2013-02-21
  • 2011-11-28
相关资源
最近更新 更多