<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