Skip to content

Commit

Permalink
依然界面不可见
Browse files Browse the repository at this point in the history
  • Loading branch information
lindexi committed Aug 24, 2024
1 parent 2a510c4 commit fc81cd9
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Workbench/HuremluhuhaChilejelawlai/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using Microsoft.Graphics.Canvas.UI.Composition;
using Microsoft.Graphics.DirectX;
using Microsoft.UI;
using Microsoft.UI.Composition;
using Microsoft.UI.Xaml.Hosting;

namespace FinayfuweewawWakibawlu;

Expand Down Expand Up @@ -70,7 +72,10 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)
{
var canvasDevice = new CanvasDevice();
var compositionGraphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(window.Compositor, canvasDevice);
var compositor = window.Compositor;
var compositionGraphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(compositor, canvasDevice);
var compositionDrawingSurface = compositionGraphicsDevice.CreateDrawingSurface(
new Windows.Foundation.Size(100, 100),
DirectXPixelFormat.B8G8R8A8UIntNormalized,
Expand All @@ -79,6 +84,18 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)
{
drawingSession.FillRectangle(new Rect(10, 10, 10, 10), Windows.UI.Color.FromArgb(0xFF, 0x56, 0x56, 0x56));
}
// 在 Win2d 渲染到平面完成之后,将这个平面作为一个画刷用于在之后的效果
CompositionSurfaceBrush surfaceBrush = compositor.CreateSurfaceBrush(compositionDrawingSurface);
SpriteVisual visual = compositor.CreateSpriteVisual();
visual.Brush = surfaceBrush;
Visual elementVisual = ElementCompositionPreview.GetElementVisual(window.Content);
if (elementVisual is ContainerVisual containerVisual)
{
containerVisual.Children.InsertAtTop(visual);
}
};

window.Activate();
Expand Down

0 comments on commit fc81cd9

Please sign in to comment.