Part 8: TripPlanner - A Complete WPF and XAML Application in Visual Basic

106 6
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------


In this window, I've chosen to design the form with DockPanel and StackPanel components. Here's the WPF code:

<Window x:Class="MainWindow"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   Title="Trip Planner"
      Height="320" Width="440"
      FontFamily="Forte" FontSize="18" FontStyle="Normal"
      WindowStyle="ThreeDBorderWindow"
      Icon="EARTH.ICO">
      <DockPanel VerticalAlignment="Stretch" Width="400">
         <StackPanel Height="230"
                  DockPanel.Dock="Top" >
      <Label Name="TripNameDisplay"
          Height="40"
          HorizontalAlignment="Stretch" />
            <ListBox Name="TripDateList"
                Height="200"
                HorizontalAlignment="Stretch"
                FontFamily="Tahoma" />
      </StackPanel>
      <Button Name="GetTripDesc"
            Height="40" DockPanel.Dock="Left"
            VerticalContentAlignment="Center"
            VerticalAlignment="Bottom"
            Width="200">
            About This Trip
         </Button>
      <Button Name="AddADay"
            Height="40"
            VerticalAlignment="Bottom"
            HorizontalAlignment="Left"
            Width="200">
         Add a Day ...
      </Button>
   </DockPanel>
</Window>


Note that the lowest level child is a ListBox. All the dates in the trip will be displayed there and I can double-click on any individual element to change the information for that date.

And the VB code for this form:

Class MainWindow

   Private Sub GetTripDesc_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.Windows.RoutedEventArgs) _
      Handles GetTripDesc.Click
      Dim MyTrip As New TripDesc
      MyTrip.ShowDialog()
      TripInfoRefresh()
   End Sub
   Private Sub MainWindow_Loaded( _
      ByVal sender As Object, _
      ByVal e As System.Windows.RoutedEventArgs) _
      Handles Me.Loaded
      TripInfoRefresh()
   End Sub
   Private Sub AddADay_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.Windows.RoutedEventArgs) _
      Handles AddADay.Click
      Dim NewDay As New AddADay
      NewDay.Tag = "A" ' AddADay Called Through Click
      NewDay.ShowDialog()
      TripInfoRefresh()
   End Sub
   Public Sub TripInfoRefresh()
      Dim TripInformation = XDocument.Load("TripInfo.xml")
      Dim theTripDates = TripInformation...<TripDate>
      TripDateList.Items.Clear()
      For Each Item In theTripDates
         TripDateList.Items.Add(Item.Value)
      Next
      TripNameDisplay.Content = _
         TripInformation...<TripName>.Value
   End Sub
   Private Sub TripDateList_MouseDoubleClick( _
      ByVal sender As Object, _
      ByVal e As System.Windows.Input.MouseButtonEventArgs) _
      Handles TripDateList.MouseDoubleClick
      Dim NewDay As New AddADay
      NewDay.Tag = TripDateList.SelectedItem
      NewDay.ShowDialog()
      TripInfoRefresh()
   End Sub
End Class


On the next page, MainWindow is explained!
Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.