private async void OnUriChanged() { if (_uri == null) { ReleaseContent(); return; } _surface = await SurfaceLoader.LoadFromUri(_uri); if (_loadEffectDelegate != null) { _effectSurface = await SurfaceLoader.LoadFromUri(_uri, Size.Empty, _loadEffectDelegate); } // Async operations may take a while. If we've unloaded, return now. if (_unloaded) { ReleaseContent(); return; } // Apply stretching policy ApplyStretchingPolicy(new Size(ActualWidth, ActualHeight)); if (_effectBrush == null) { CompositionSurfaceBrush brush = (CompositionSurfaceBrush)_sprite.Brush; if (brush != null) { brush.Surface = _surface; } else { _sprite.Brush = _compositor.CreateSurfaceBrush(_surface); } } else { _effectBrush.SetSourceParameter("ImageSource", _compositor.CreateSurfaceBrush(_surface)); if (_effectSurface != null) { _effectBrush.SetSourceParameter("EffectSource", _compositor.CreateSurfaceBrush(_effectSurface)); } _sprite.Brush = _effectBrush; } }
public async void SetEffectBrush(CompositionEffectBrush brush) { // Release previous brush if set if (_effectBrush != null) { _effectBrush.Dispose(); _effectBrush = null; } if (_effectSurface != null) { _effectSurface.Dispose(); _effectSurface = null; } _effectBrush = brush; // Set the new brush if (_sprite != null) { // Release current brush if (_sprite.Brush != null) { _sprite.Brush.Dispose(); } if (_surface != null) { // If the effect brush is cleared, create a surface brush if (_effectBrush == null) { _sprite.Brush = _compositor.CreateSurfaceBrush(_surface); } else { _effectBrush.SetSourceParameter("ImageSource", _compositor.CreateSurfaceBrush(_surface)); if (_loadEffectDelegate != null) { _effectSurface = await SurfaceLoader.LoadFromUri(_uri, Size.Empty, _loadEffectDelegate); _effectBrush.SetSourceParameter("EffectSource", _compositor.CreateSurfaceBrush(_effectSurface)); } _sprite.Brush = _effectBrush; } } } }