I'm having trouble binding data to the Modern UI Chart control.
Im not using it the common way where i create a XAML element and then bind to that, my goal is to create the element and render it in memory for then to fetch the image of the element.
My code below is for the creation and adding of content, the rendering of the image works fine.
void generateGraphImg()
{
PieChart pc = new PieChart();
ObservableCollection<TestClass> Errors = new ObservableCollection<TestClass>();
Errors.Add(new TestClass() { Category = "Globalization", Number = 75 });
Errors.Add(new TestClass() { Category = "Features", Number = 2 });
Errors.Add(new TestClass() { Category = "ContentTypes", Number = 12 });
Errors.Add(new TestClass() { Category = "Correctness", Number = 83 });
Errors.Add(new TestClass() { Category = "Best Practices", Number = 29 });
ChartSeries Charts = new ChartSeries();
Charts.SeriesTitle = "Errors";
Charts.DisplayMember = "Category";
Charts.ValueMember = "Number";
Charts.ItemsSource = Errors;
pc.Series.Add(Charts);
pc.ChartTitle = "Minimal Pie Chart";
pc.ChartSubTitle = "Chart with fixed width and height";
makeImgFromControl(pc, @"C:\Modern UI IMG\img.bmp");
}
void makeImgFromControl(UIElement control, string saveTo)
{
Viewbox viewbox = new Viewbox();
viewbox.Child = control; //control to render
viewbox.Measure(new System.Windows.Size(200, 200));
viewbox.Arrange(new Rect(0, 0, 200, 200));
viewbox.UpdateLayout(); //On PiePiece DrawGeometry() happens here
RenderTargetBitmap render = new RenderTargetBitmap(500,500, 150, 150, PixelFormats.Pbgra32);
render.Render(viewbox);
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(render));
using (Stream s = File.Create(saveTo))
{
encoder.Save(s);
}
}
The binding of data does not render but, the title and sub-title renders fine any ideas to why?