Windows Scripting
  Home arrow Windows Scripting arrow Page 3 - Data Converstion and Task Addition with WP...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Data Converstion and Task Addition with WPF
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-09-08

    Table of Contents:
  • Data Converstion and Task Addition with WPF
  • Converting Values, Continued
  • Adding Tasks
  • Adding Tasks, Continued

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Data Converstion and Task Addition with WPF - Adding Tasks


    (Page 3 of 4 )

    We now need to create a way to add tasks to the list. The easiest way to do this is to create an "Add Task" dialog that's shown when the user clicks the "Add Task" button. The dialog will prompt the user for the required information (title, priority and description), and when the "Okay" button is clicked, the new task will be added to the list.

    The dialog will require a new window. Add a new Window (WPF) to the project called AddTaskDialog.xaml. Visual Studio will then create the basic XAML for the window. The default height of the new window is too big for our needs, so we'll need to decrease it a bit. The title should also be changed to something more appropriate:


    <Window x:Class="WpfToDo.AddTaskDialog"

     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

      Title="Add Task" Height="250" Width="300">


    Next, the dialog needs some controls. For the title, a TextBox control will do; for the priority, a ComboBox control will do; and for the description, a TextBox control with wrapping will do. These input controls will need labels. Two buttons will also be necessary, an "Okay" button and a "Cancel" button.


    It's best that the controls be organized into a grid of five rows and three columns in order to achieve a look like this (the grid lines are shown by setting the ShowGridLines attribute of Grid to True):



    I'll go ahead and place all the required XAML below. Most of it should be familiar to you, and so I'll only explain a few parts in bold:


    <Grid HorizontalAlignment="Center" VerticalAlignment="Center">

     <Grid.RowDefinitions>

     <RowDefinition Height="25" />

     <RowDefinition Height="25" />

     <RowDefinition Height="25" />

     <RowDefinition Height="100" />

     <RowDefinition Height="25" />

     </Grid.RowDefinitions>

     <Grid.ColumnDefinitions>

     <ColumnDefinition Width="75" />

     <ColumnDefinition Width="75" />

     <ColumnDefinition Width="125" />

     </Grid.ColumnDefinitions>

     

     <Label Grid.Row="0" Grid.Column="0" Content="Title:" />

     <TextBox Name="TaskTitle" Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" />

     <Label Grid.Row="1" Grid.Column="0" Content="Priority:" Margin="0,3,0,0" />

     <ComboBox Name="TaskPriority" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" SelectedIndex="0" Margin="0,3,0,0">

     <ComboBoxItem Foreground="Green">Low</ComboBoxItem>

     <ComboBoxItem Foreground="Orange">Medium</ComboBoxItem>

     <ComboBoxItem Foreground="Red">High</ComboBoxItem>

     </ComboBox>

     <Label Grid.Row="2" Grid.Column="0" Content="Description:" Margin="0,3,0,0" />

     <TextBox Name="TaskDescription" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3" TextWrapping="Wrap" Margin="0,3,0,0" />

     <Button Name="OkayButton" Grid.Row="4" Grid.Column="0" Content="Okay" Margin="0,3,2,0" />

     <Button Name="CancelButton" Grid.Row="4" Grid.Column="1" IsCancel="True" Content="Cancel" Margin="2,3,0,0" />

    </Grid>


    The ComboBox control is pretty simple to understand, but it's nonetheless new and merits being pointed out. Notice how the priorities are colored as they are in the task list itself.

    In order to wrap text in the description TextBox, the TextWrapping attribute is set to Wrap.

    The IsCancel attribute of the cancel button is set to True. This way, if the user presses escape, the button will automatically be "clicked."

    Next, the dialog needs to respond to the okay button being clicked. If the button is clicked, then the window's DialogResult property must be set to true. This will close the dialog and return true (as described below). Either double click the button in the designer or add an event handler through XAML:


    <Button Name="OkayButton" Grid.Row="4" Grid.Column="0" Content="Okay" Margin="0,3,2,0" Click="OkayButton_Click" />


    The event handler operates exactly as described above:


    private void OkayButton_Click(object sender, RoutedEventArgs e)

    {

    DialogResult = true;

    }


    More Windows Scripting Articles
    More By Peyton McCullough


       · Hello,In this third article of my series on WPF, we implement some of the...
     

    WINDOWS SCRIPTING ARTICLES

    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...
    - Modifying XML Files in WSH
    - Reading XML Files in WSH
    - Visual Basic 2005 XML Programming Using XML ...
    - Creating an XML Document in WSH
    - Introducing Two-Way Data Binding using Silve...
    - Silverlight 2.0 Application Development with...
    - Burning Multisession CDs with IMAPI2 in WSH
    - Creating a Silverlight 2.0 Application that ...
    - Burning CDs with the IMAPI2 Control
    - Burning CDs in Windows XP with WSH

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT