Hello World Application in WPF
WPF – Windows Presentation Foundation is the next generation technology from Microsoft. You can get more information about WPF from this site WPF on MSDN. I got the oppurtunity to work on WPF application project on my company. I am giving the source code of a WPF Text File Viewer application.
Happy WPF Programming
xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
Title=”WPF Text File Viewer” Height=”300″ Width=”500″ Opacity=”20″ Loaded=”Window_Loaded”>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height=”Auto”/>
<RowDefinition Height=”*”/>
<RowDefinition Height=”Auto”/>
</Grid.RowDefinitions>
<Menu Grid.Row=”0″ Grid.Column=”0″ >
<MenuItem Header=”_File”>
<MenuItem Header=”_Open” Name=”Open” Click=”Open_Click” />
<Separator/>
<MenuItem Header=”_Exit” Name=”Exit” Click=”Exit_Click” />
</MenuItem><MenuItem Header=”_Help”>
<MenuItem Header=”_About” Name=”About” Click=”About_Click”/>
</MenuItem></Menu>
<TextBox Grid.Row=”1″ Grid.Column=”0″ Name=”txtEntry” AcceptsReturn=”True” AcceptsTab=”True” HorizontalScrollBarVisibility=”Auto” VerticalScrollBarVisibility=”Auto” IsReadOnly=”True”></TextBox>
<StatusBar Grid.Row=”2″>
<StatusBarItem>
<TextBlock Name=”txtStatus”></TextBlock>
</StatusBarItem>
</StatusBar>
</Grid>
</Window>
And the code behind for the XAML
Private m_title As String = “WPF Text File viewer”
Private Sub Open_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
Dim OpenfileDlg As New Microsoft.Win32.OpenFileDialog
OpenfileDlg.Multiselect = False
OpenfileDlg.Filter = “Text Files only|*.txt”
OpenfileDlg.ReadOnlyChecked = True
If OpenfileDlg.ShowDialog Then
ShowFile(OpenfileDlg.FileName)
End If
End SubPrivate Sub ShowFile(ByVal Filename As String)
Using file As New IO.StreamReader(Filename)
Me.txtEntry.Text = file.ReadToEnd()
Me.Title = String.Format(“{0} – {1}”, IO.Path.GetFileNameWithoutExtension(Filename), m_title)
End Using
End Sub
Private Sub Exit_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)Me.Close()
End SubPrivate Sub About_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)MessageBox.Show(String.Format(“{0}{1}A simple utility to view text files in WPF”, m_title, Environment.NewLine), m_title, MessageBoxButton.OK, MessageBoxImage.Information)
End Sub
Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
Me.txtStatus.Text = String.Format(“Welcome to {0}”, m_title)
End Sub
End Class
No Responses to “Hello World Application in WPF”
RSS feed for comments on this post. TrackBack URL