/// <summary> /// Renders the XAML contained within a file to the specified ImageFormat and writes it to the Stream /// </summary> /// <param name="xamlPath">The path of the XAML file to render</param> /// <param name="dataContext">The DataContext to pass to the XAML control</param> /// <param name="streamToWriteTo">The Stream to write the renderd image to</param> /// <param name="imageFormat">The ImageFormat to encode the rendered image</param> public static void RenderPath(string xamlPath, object dataContext, Stream streamToWriteTo, ImageFormat imageFormat) { using (var img = new XamlImage { Path = xamlPath, DataContext = dataContext, ImageFormat = imageFormat }) { img.Render(); if (img.Stream != null) { img.Stream.WriteTo(streamToWriteTo); } } }
public void Render(ViewContext viewContext, System.IO.TextWriter writer) { object dataContext = null; if (viewContext.ViewData.Model != null) { dataContext = viewContext.ViewData.Model; } else { dataContext = (dynamic)(new DynamicDictionary(viewContext.ViewData)); } var xamlPath = viewContext.HttpContext.Server.MapPath(this.ViewPath); var response = viewContext.HttpContext.Response; response.ContentType = GetContentType(this.ImageFormat); XamlImage.RenderPath(xamlPath, dataContext, response.OutputStream, this.ImageFormat); }
/// <summary> /// Renders the XAML contained within a file to PNG format and writes it to the Stream /// </summary> /// <param name="xamlPath">The path of the XAML file to render</param> /// <param name="dataContext">The DataContext to pass to the XAML control</param> /// <param name="streamToWriteTo">The Stream to write the renderd image to</param> public static void RenderPath(string xamlPath, object dataContext, Stream streamToWriteTo) { XamlImage.RenderPath(xamlPath, dataContext, streamToWriteTo, ImageFormat.Png); }
/// <summary> /// Renders the XAML contained within a file to PNG format and writes it to the Stream /// </summary> /// <param name="xamlPath">The path of the XAML file to render</param> /// <param name="streamToWriteTo">The Stream to write the renderd image to</param> public static void RenderPath(string xamlPath, Stream streamToWriteTo) { XamlImage.RenderPath(xamlPath, null, streamToWriteTo); }