Create an instance of Viewbox in code. Use Viewbox to stretch or scale a single child element. : Viewbox « Windows Presentation Foundation « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » Windows Presentation Foundation » Viewbox 
24.65.2.Create an instance of Viewbox in code. Use Viewbox to stretch or scale a single child element.
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Threading;


  public class app : System.Windows.Application
  {
        System.Windows.Controls.Canvas myCanvas;
    System.Windows.Window mainWindow;
        System.Windows.Controls.Viewbox myViewbox;
        System.Windows.Controls.Grid myGrid;
        System.Windows.Controls.TextBlock myTextBlock;
        System.Windows.Shapes.Ellipse myEllipse;

    protected override void OnStartup (StartupEventArgs e)
    {
      base.OnStartup (e);
      mainWindow = new System.Windows.Window ();

      myCanvas = new Canvas();
            myCanvas.Background = System.Windows.Media.Brushes.Silver;
            myCanvas.Width = 600;
            myCanvas.Height = 600;
            
            myViewbox = new Viewbox();
            myViewbox.StretchDirection = StretchDirection.Both;
            myViewbox.Stretch = Stretch.Fill;
            myViewbox.MaxWidth = 400;
            myViewbox.MaxHeight = 400;

            myGrid = new Grid();
            myEllipse = new Ellipse();
            myEllipse.Stroke = Brushes.RoyalBlue;
            myEllipse.Fill = Brushes.LightBlue;

            myTextBlock = new TextBlock();
            myTextBlock.Text = "Viewbox";

            myGrid.Children.Add(myEllipse);
            myGrid.Children.Add(myTextBlock);

            myViewbox.Child = myGrid;
            
            Canvas.SetTop(myViewbox, 100);
            Canvas.SetLeft(myViewbox, 100);
            myCanvas.Children.Add(myViewbox);

            mainWindow.Content = myCanvas;
      mainWindow.Show();
    }
    [System.STAThread()]
    private static void Main ()
    {
      app app = new app ();
      app.Run ();
    }
  }
24.65.Viewbox
24.65.1.Programmatically change the Stretch and StretchDirection of content within a Viewbox.Programmatically change the Stretch and StretchDirection of content within a Viewbox.
24.65.2.Create an instance of Viewbox in code. Use Viewbox to stretch or scale a single child element.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.