private void SetSourceFromXaml(BitmapImage brush, string xaml) { try { var fe = XamlReader.Load(xaml) as FrameworkElement; fe.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); fe.Arrange(new Rect(0, 0, fe.DesiredSize.Width, fe.DesiredSize.Height)); WriteableBitmap bmp = new WriteableBitmap(fe, null); var stream = bmp.SaveAsPng(); brush.SetSource(stream); } catch { } }