BlurEffect.MainPage.LayoutRoot_Loaded C# (CSharp) Method

LayoutRoot_Loaded() private method

private LayoutRoot_Loaded ( object sender, RoutedEventArgs e ) : void
sender object
e Windows.UI.Xaml.RoutedEventArgs
return void
        void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {
            // get visuals from xaml object
            _touchAreaVisual = GetVisual(this.TouchArea);
            var imagePanelVisual = GetVisual(this.ImagePanel);

            // get compositor
            _compositor = imagePanelVisual.Compositor;

            var width = (float)this.ImagePanel.ActualWidth;
            var height = (float)this.ImagePanel.ActualHeight;

            // load the background image
            var uri = new Uri("ms-appx:///Assets/White.png");
            var imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor);
            var options = new CompositionImageOptions
            {
                DecodeWidth = (int)width,
                DecodeHeight = (int)height
            };
            var image = imageFactory.CreateImageFromUri(uri, options);

            // currently GaussianBlurEffect is not supported in Composition
            var effectDefination = new SaturationEffect // new GaussianBlurEffect
            {
                //BorderMode = EffectBorderMode.Soft,
                //BlurAmount = 5f,
                //Optimization = EffectOptimization.Quality,
                Source = new CompositionEffectSourceParameter("Overlay")
            };

            // create the actual effect
            var surfaceBrush = _compositor.CreateSurfaceBrush(image.Surface);
            var effectFactory = _compositor.CreateEffectFactory(effectDefination);
            var effectBrush = effectFactory.CreateBrush();
            effectBrush.SetSourceParameter("Overlay", surfaceBrush);

            // create the visual with the effect
            _visual = _compositor.CreateSpriteVisual();
            _visual.Brush = effectBrush;
            _visual.Opacity = 0.8f;
            _visual.Size = new Vector2(width, height);

            // place the effect visual onto the UI
            imagePanelVisual.Children.InsertAtTop(_visual);
        }