Programmatically change the Stretch and StretchDirection of content within a Viewbox. : Viewbox « Windows Presentation Foundation « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » Windows Presentation Foundation » Viewbox 
16.40.7.Programmatically change the Stretch and StretchDirection of content within a Viewbox.
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="Viewbox_Stretch_Layout_Samp.Window1"
    Title="ViewBox Stretch and StretchDirection Sample">

  <DockPanel Background="White">
        <StackPanel HorizontalAlignment="Center" Orientation="Horizontal" DockPanel.Dock="Top">
            <Button Name="btn1" Click="stretchNone">Stretch="None"</Button>
            <Button Name="btn2" Click="stretchFill">Stretch="Fill"</Button>
            <Button Name="btn3" Click="stretchUni">Stretch="Uniform"</Button>
            <Button Name="btn4" Click="stretchUniFill">Stretch="UniformToFill"</Button>
            <Button Name="btn5" Click="sdUpOnly">StretchDirection="UpOnly"</Button>
            <Button Name="btn6" Click="sdDownOnly">StretchDirection="DownOnly"</Button>
            <Button Name="btn7" Click="sdBoth">StretchDirection="Both"</Button>
         </StackPanel>        
        
        <TextBlock DockPanel.Dock="Top" Name="txt1" />
        <TextBlock DockPanel.Dock="Top" Name="txt2" />
        
        <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
            <Viewbox MaxWidth="500" MaxHeight="500" Name="vb1">
                <Image Source="c:\image.jpg"/>
            </Viewbox>    
        </StackPanel>
  </DockPanel>
</Window>

//File:Window.xaml.vb

Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents

Namespace Viewbox_Stretch_Layout_Samp
  Public Partial Class Window1
    Inherits Window
    Public Sub stretchNone(sender As Object, e As RoutedEventArgs)
      vb1.Stretch = System.Windows.Media.Stretch.None
      txt1.Text = "Stretch is now set to None."
    End Sub

    Public Sub stretchFill(sender As Object, e As RoutedEventArgs)
      vb1.Stretch = System.Windows.Media.Stretch.Fill
      txt1.Text = "Stretch is now set to Fill."
    End Sub

    Public Sub stretchUni(sender As Object, e As RoutedEventArgs)
      vb1.Stretch = System.Windows.Media.Stretch.Uniform
      txt1.Text = "Stretch is now set to Uniform."
    End Sub

    Public Sub stretchUniFill(sender As Object, e As RoutedEventArgs)
      vb1.Stretch = System.Windows.Media.Stretch.UniformToFill
      txt1.Text = "Stretch is now set to UniformToFill."
    End Sub

    Public Sub sdUpOnly(sender As Object, e As RoutedEventArgs)
      vb1.StretchDirection = System.Windows.Controls.StretchDirection.UpOnly
      txt2.Text = "StretchDirection is now UpOnly."
    End Sub

    Public Sub sdDownOnly(sender As Object, e As RoutedEventArgs)
      vb1.StretchDirection = System.Windows.Controls.StretchDirection.DownOnly
      txt2.Text = "StretchDirection is now DownOnly."
    End Sub

    Public Sub sdBoth(sender As Object, e As RoutedEventArgs)
      vb1.StretchDirection = System.Windows.Controls.StretchDirection.Both
      txt2.Text = "StretchDirection is now Both."
    End Sub
  End Class
End Namespace
WPF Programmatically Change The Stretch And Stretch Direction Of Content Within A Viewbox
16.40.Viewbox
16.40.1.Specifying a ViewboxSpecifying a Viewbox
16.40.2.Viewbox with absolute unitsViewbox with absolute units
16.40.3.Using Viewbox and put Canvas into itUsing Viewbox and put Canvas into it
16.40.4.Specifying a Stretch for ViewBoxSpecifying a Stretch for ViewBox
16.40.5.ViewBox StretchDirectionViewBox StretchDirection
16.40.6.Radial gradient fillsRadial gradient fills
16.40.7.Programmatically change the Stretch and StretchDirection of content within a Viewbox.Programmatically change the Stretch and StretchDirection of content within a Viewbox.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.