3 using System
.Windows
.Controls
;
4 using System
.Windows
.Media
;
5 using System
.Windows
.Shapes
;
6 using System
.Threading
;
10 public class app
: System
.Windows
.Application
12 System
.Windows
.Controls
.Canvas myCanvas
;
13 System
.Windows
.Window mainWindow
;
14 System
.Windows
.Controls
.Viewbox myViewbox
;
15 System
.Windows
.Controls
.Grid myGrid
;
16 System
.Windows
.Controls
.TextBlock myTextBlock
;
17 System
.Windows
.Shapes
.Ellipse myEllipse
;
19 protected override void OnStartup (StartupEventArgs e
)
22 CreateAndShowMainWindow ();
25 private void CreateAndShowMainWindow ()
27 // Create the application's main window
28 mainWindow
= new System
.Windows
.Window ();
30 // Create a Canvas sized to fill the window
31 myCanvas
= new Canvas();
32 myCanvas
.Background
= System
.Windows
.Media
.Brushes
.Silver
;
34 myCanvas
.Height
= 600;
37 // Create a Viewbox and add it to the Canvas
38 myViewbox
= new Viewbox();
39 myViewbox
.StretchDirection
= StretchDirection
.Both
;
40 myViewbox
.Stretch
= Stretch
.Fill
;
41 myViewbox
.MaxWidth
= 400;
42 myViewbox
.MaxHeight
= 400;
44 // Create a Grid that will be hosted inside the Viewbox
47 // Create an Ellipse that will be hosted inside the Viewbox
48 myEllipse
= new Ellipse();
49 myEllipse
.Stroke
= Brushes
.RoyalBlue
;
50 myEllipse
.Fill
= Brushes
.LightBlue
;
52 // Create an TextBlock that will be hosted inside the Viewbox
53 myTextBlock
= new TextBlock();
54 myTextBlock
.Text
= "Viewbox";
56 // Add the children to the Grid
57 myGrid
.Children
.Add(myEllipse
);
58 myGrid
.Children
.Add(myTextBlock
);
61 // Add the Grid as the single child of the Viewbox
62 myViewbox
.Child
= myGrid
;
65 // Position the Viewbox in the Parent Canvas
66 Canvas
.SetTop(myViewbox
, 100);
67 Canvas
.SetLeft(myViewbox
, 100);
68 myCanvas
.Children
.Add(myViewbox
);
71 // Set the Window content
72 mainWindow
.Content
= myCanvas
;
78 internal static class EntryClass
81 private static void Main ()