Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
380
XamDataChart off screen rendering
posted

I have a requirement to include some images from our XamDataCharts(scatter and column) into seperate RTF reporting part of the application. The problem is that the placeholders for the charts are different sizes than the chart visualization page. I tried a couple of different things to resize the images but nothing looked right.  I tried to clone the control using XamlWriter.Save() but it just hung.  So I decided to create an in memory copy of the control, bind it up, set it to the desired size, and then call rendertargetbitmap to grab the image.  This worked great for the 'generic' controls on the page but the xamdatachart resized but would not show the actual chart data.

        public BitmapSource GetBar()
        {
            var vm = DataContext as MyChartViewModel;
            var are = new AutoResetEvent(false);
            var lc = new myBarChart { DataContext = vm };
            lc.Data = vm.BarChartData;
            lc.BarChartSource = vm.SelectectedBarChartDisplayMode.SourceType;
            lc.Width = 350;
            lc.Height = 400;
            lc.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Loaded,
                                 new Action(() => { are.Set(); }));
 
            are.WaitOne(2500);
            lc.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            lc.Arrange(new Rect(lc.DesiredSize));
            return lc.Export();//calls rendertargetbitmap
        }
Parents
No Data
Reply
  • 380
    posted

    Found my own problem, I was missing an updatelayout after the measure and arrange.

    So now it works the question remains if this is the best method to accomplish my goal...

Children