New Features of Windows 10 Creaters Update-image-in-painting mode and window Gaussian blur
In Windows 10 Creaters Update, you can set Gaussian Blur for the window, just a few lines of code!
<Grid Loaded="Grid_Loaded"> <Grid x:Name="mg"></Grid> <Grid Background="Blue" Opacity="0.4" x:Name="rootGrid" ></Grid> <!--your uielements--> </Grid>
Windows.UI.Composition.Compositor _compositor; Windows.UI.Composition.SpriteVisual _hostSprite; public MainPage() { this.InitializeComponent(); _compositor = Windows.UI.Xaml.Hosting.ElementCompositionPreview.GetElementVisual(this).Compositor; } private void Grid_Loaded(object sender, RoutedEventArgs e) { _hostSprite = _compositor.CreateSpriteVisual(); _hostSprite.Size = new System.Numerics.Vector2((float)rootGrid.ActualWidth, (float)rootGrid.ActualHeight); ElementCompositionPreview.SetElementChildVisual(mg, _hostSprite); _hostSprite.Brush = _compositor.CreateHostBackdropBrush(); }
Effect
The color of the Grid in XAML can be changed and deleted. That is to blur the specific color of the Start Menu.
However, this method does not work in the newly added image-in-picture mode.
It's actually very easy to learn how to implement in-picture
Check whether image-in-picture is supported
ApplicationView.GetForCurrentView().IsViewModeSupported(ApplicationViewMode.CompactOverlay)
Go to painting
bool modeSwitched = await ApplicationView.GetForCurrentView().TryEnterViewModeAsync(ApplicationViewMode.CompactOverlay);
ViewModePreferences compactOptions = ViewModePreferences. createDefault (ApplicationViewMode. compactOverlay); compactOptions. customSize = new Windows. foundation. size (320,200); // the Size of the window you want bool modeSwitched = await ApplicationView. getForCurrentView (). tryEnterViewModeAsync (ApplicationViewMode. default, compactOptions );
Exit from painting
bool modeSwitched = await ApplicationView.GetForCurrentView().TryEnterViewModeAsync(ApplicationViewMode.Default);
You can also combine the UWP Multi-Window Function
Await CoreApplication. createNewView (). dispatcher. runAsync (CoreDispatcherPriority. normal, () => {var frame = new Frame (); compactViewId = ApplicationView. getForCurrentView (). id; frame. navigate (typeof (SecondaryCompactViewPage); Window. current. content = frame; Window. current. activate (); ApplicationView. getForCurrentView (). title = "painting window" ;}); bool viewShown = await ApplicationViewSwitcher. tryShowAsViewModeAsync (compactViewId, ApplicationViewMode. compactOverlay );
Microsoft multi-window example: https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/MultipleViews
Introduction to the function of picture-in-picture: https://blogs.msdn.microsoft.com/universal-windows-app-model/2017/02/11/compactoverlay-mode-aka-picture-in-picture/
I also made a complete example where you can download the https://git.oschina.net/PixeezPlus/Sharp2DDemo/tree/master/GaussianBlurWindow here
Note that the code is only valid for the Creaters Update and later versions of the PC.