Skip to content

Instantly share code, notes, and snippets.

@terriblememory
Created October 12, 2017 16:05
Show Gist options
  • Save terriblememory/78f1faca77941c43c4a887025e370ee5 to your computer and use it in GitHub Desktop.
Save terriblememory/78f1faca77941c43c4a887025e370ee5 to your computer and use it in GitHub Desktop.
XamlCompositionBrushBase example
public class ExampleBrush : XamlCompositionBrushBase
{
protected override void OnConnected()
{
if (CompositionBrush == null)
{
var compositor = Window.Current.Compositor;
var bitmapUri = new System.Uri("ms-appx:///Assets/StoreLogo.png");
var bitmapSurface = LoadedImageSurface.StartLoadFromUri(bitmapUri);
var bitmapBrush = compositor.CreateSurfaceBrush(bitmapSurface);
bitmapBrush.Stretch = CompositionStretch.None;
CompositionBrush = bitmapBrush;
}
}
protected override void OnDisconnected()
{
if (CompositionBrush != null)
{
CompositionBrush.Dispose();
CompositionBrush = null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment