Launch a window with defined XAML : Window « 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 » Window 
16.57.17.Launch a window with defined XAML
<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     Title="Simple XAMl Viewer" Height="338" Width="1041" 
    Loaded="Window_Loaded" Closed="Window_Closed" WindowStartupLocation="CenterScreen" >
  <DockPanel  LastChildFill="True" >
    <Button DockPanel.Dock="Top"  Name = "btnViewXaml" Width="100" Height="40"
              Content ="View Xaml" Click="btnViewXaml_Click" />
    <TextBox AcceptsReturn ="True" Name ="txtXamlData"
       BorderBrush ="Blue" VerticalScrollBarVisibility="Auto" AcceptsTab="True" TextDecorations="None">
    </TextBox>
  </DockPanel>
</Window>
//File:Window.xaml.vb
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Navigation
Imports System.Windows.Shapes

Imports System.IO
Imports System.Windows.Markup

Namespace WpfApplication1
  Public Partial Class MainWindow
    Inherits Window
    Public Sub New()
      InitializeComponent()
    End Sub

    Private Sub btnViewXaml_Click(sender As Object, e As RoutedEventArgs)
      File.WriteAllText("YourXaml.xaml", txtXamlData.Text)
      Dim myWindow As Window = Nothing
      Try
        Using sr As Stream = File.Open("YourXaml.xaml", FileMode.Open)
          myWindow = DirectCast(XamlReader.Load(sr), Window)
          myWindow.ShowDialog()
        End Using
      Catch ex As Exception
        MessageBox.Show(ex.Message)
      End Try
    End Sub
    Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
      txtXamlData.Text = "<Window xmlns=""http://schemas.microsoft.com" "/winfx/2006/xaml/presentation""" & vbLf & "xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""" " Height =""400"" Width =""500"" WindowStartupLocation=""CenterScreen"">" & vbLf & "<StackPanel>" & vbLf & "</StackPanel>" & vbLf & "</Window>"
    End Sub
    Private Sub Window_Closed(sender As Object, e As EventArgs)
      File.WriteAllText("YourXaml.xaml", txtXamlData.Text)
    End Sub
  End Class
End Namespace
WPF Launch A Window With Defined X A M L
16.57.Window
16.57.1.Custom WindowCustom Window
16.57.2.Set window size in XAMLSet window size in XAML
16.57.3.A simple user-login XAML pageA simple user-login XAML page
16.57.4.User login screen with no layout or formattingUser login screen with no layout or formatting
16.57.5.Automatically Size the Main Application Window to Accommodate Its ContentAutomatically Size the Main Application Window to Accommodate Its Content
16.57.6.Window OwnershipWindow Ownership
16.57.7.Creating the main panel and add to Window in CodeCreating the main panel and add to Window in Code
16.57.8.Show window based on button nameShow window based on button name
16.57.9.Set a Default ButtonSet a Default Button
16.57.10.Window with Menu, ToolBar, StatusBarWindow with Menu, ToolBar, StatusBar
16.57.11.Order of precedence for sizing-related properties that are implemented by Window.Order of precedence for sizing-related properties that are implemented by Window.
16.57.12.Use Window Activated and Deactivated event to control a media fileUse Window Activated and Deactivated event to control a media file
16.57.13.Animated Video WindowAnimated Video Window
16.57.14.Use WindowState to make full screen window, change resize mode to NoReSizeUse WindowState to make full screen window, change resize mode to NoReSize
16.57.15.Do not handle events until Window is fully initialized.Do not handle events until Window is fully initialized.
16.57.16.Load resource from Window ResourcesLoad resource from Window Resources
16.57.17.Launch a window with defined XAMLLaunch a window with defined XAML
16.57.18.Display window as dialogDisplay window as dialog
16.57.19.Save Window Position to RegistrySave Window Position to Registry
16.57.20.Center a Window to ScreenCenter a Window to Screen
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.