1. Computing & Technology

Discuss in my forum

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

The AddADay Code and the System Download

By , About.com Guide

See More About:

Here's the AddADay code

Partial Public Class AddADay
   Dim TripInformation As XDocument
   Private Sub AddADay_Loaded( _
      ByVal sender As Object, _
      ByVal e As System.Windows.RoutedEventArgs) _
      Handles Me.Loaded
      If Me.Tag = "A" Then
         AddADay() ' AddADay called through click
      Else
         ' AddADay called by double clicking date
         StayAtDate.Text = Me.Tag
         TripInformation = _
            XDocument.Load("TripInfo.xml")
         Dim StayAtElement = _
            From TripDate _
            In TripInformation...<TripDate> _
            Where TripDate = StayAtDate.Text
         StayAtDesc.Text = StayAtElement.@<StayAt>
         TransDesc.Text = StayAtElement.@<Trans>
         EventsDesc.Text = StayAtElement.@<Events>
      End If
   End Sub
   Private Sub ExitDesc_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.Windows.RoutedEventArgs) _
      Handles ExitDesc.Click
      Me.Close()
   End Sub
   Private Sub ContentChanged( _
      ByVal sender As System.Object, _
      ByVal e As System.Windows.RoutedEventArgs) _
      Handles StayAtDesc.LostFocus, _
            TransDesc.LostFocus, _
            EventsDesc.LostFocus
      TripInformation = XDocument.Load("TripInfo.xml")
      Dim StayAtElement = _
         From TripDate _
         In TripInformation...<TripDate> _
         Where TripDate = StayAtDate.Text
      Select Case e.Source.name
         Case "StayAtDesc"
            StayAtElement.@StayAt = StayAtDesc.Text
         Case "TransDesc"
            StayAtElement.@Trans = TransDesc.Text
         Case "EventsDesc"
            StayAtElement.@Events = EventsDesc.Text
      End Select
      TripInformation.Save("TripInfo.xml")
   End Sub
   Private Sub AddADay()
      TripInformation = XDocument.Load("TripInfo.xml")
      Dim myTripDates = _
         From tripdates _
         In TripInformation...<TripDate>
      Dim myTripDate = _
         From tripdate _
         In TripInformation...<TripDates>
      Dim LastDate As Date = _
         Date.Parse(myTripDates.Last().Value)
      Dim LastDateString = _
         Format(LastDate.AddDays(1), "MM/dd/yyyy")
      StayAtDate.Text = LastDateString
      myTripDate(0).Add( _
         <TripDate><%= LastDateString %></TripDate>)
      TripInformation.Save("TripInfo.xml")
   End Sub
End Class

The entire project can be downloaded here.

  1. About.com
  2. Computing & Technology
  3. Visual Basic
  4. Using VB.NET
  5. WPF Tutorial Part 8: A First Introduction to WPF and XAML for Visual Basic Programmers

©2012 About.com. All rights reserved.

A part of The New York Times Company.