PageRenderTime 18ms CodeModel.GetById 2ms app.highlight 10ms RepoModel.GetById 2ms app.codeStats 0ms

/Main/src/DevSamples/BitmapBasedGraphSample/Window1.xaml.cs

#
C# | 68 lines | 60 code | 5 blank | 3 comment | 0 complexity | dc9bfb30aff47df673776a33ab193da5 MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Text;
 5using System.Windows;
 6using System.Windows.Controls;
 7using System.Windows.Data;
 8using System.Windows.Documents;
 9using System.Windows.Input;
10using System.Windows.Media;
11using System.Windows.Media.Imaging;
12using System.Windows.Navigation;
13using System.Windows.Shapes;
14using Microsoft.Research.DynamicDataDisplay;
15using System.Threading;
16
17namespace BitmapBasedGraphSample
18{
19    /// <summary>
20    /// Interaction logic for Window1.xaml
21    /// </summary>
22    public partial class Window1 : Window
23    {
24        public Window1()
25        {
26            InitializeComponent();
27        }
28    }
29
30    public class BitmapBasedSampleGraph : BitmapBasedGraph
31    {
32        protected override BitmapSource RenderFrame(DataRect dataRect, Rect output)
33        {
34            Grid grid = new Grid();
35            grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
36            grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
37            TextBlock lt = new TextBlock
38            {
39                VerticalAlignment = VerticalAlignment.Top,
40                HorizontalAlignment = HorizontalAlignment.Left,
41                Text = String.Format("({0},{1})", dataRect.XMin, dataRect.YMax)
42            };
43            grid.Children.Add(lt);
44            Grid.SetRow(lt, 0);
45            TextBlock rb = new TextBlock
46            {
47                VerticalAlignment = VerticalAlignment.Bottom,
48                HorizontalAlignment = HorizontalAlignment.Right,
49                Text = String.Format("({0},{1})", dataRect.XMax, dataRect.YMin)
50            };
51            grid.Children.Add(rb);
52            Grid.SetRow(rb, 1);
53            Border border = new Border();
54            border.BorderThickness = new Thickness(3);
55            border.BorderBrush = Brushes.Blue;
56            border.Child = grid;
57
58            RenderTargetBitmap rtb = new RenderTargetBitmap((int)output.Width, (int)output.Height, 96, 96, PixelFormats.Default);
59            border.Measure(new Size(output.Width, output.Height));
60            border.Arrange(output);
61            rtb.Render(border);
62
63            Thread.Sleep(1000);
64
65            return rtb;
66        }
67	}
68}