Windows Scripting
  Home arrow Windows Scripting arrow Page 2 - Adding Controls to an Application with WPF
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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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

Adding Controls to an Application with WPF
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-09-02

    Table of Contents:
  • Adding Controls to an Application with WPF
  • Creating the XML data file
  • Databinding
  • Working with templates

  • 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


    Adding Controls to an Application with WPF - Creating the XML data file


    (Page 2 of 4 )

    The controls are positioned correctly, and now we can turn our attention to the tasks in the to-do list. Obviously, the tasks need to be drawn from some data source. Although there are several options available, the easiest way to store and retrieve the data is through a simple XML file. Preparing this file won't require a lot of work, and the result will be readable and manageable.

    Each task needs to have a name, a description, a priority, and a status (done or not done). Describing this in XML is very easy. Each task can be represented by a Task element, and inside of each Task element can be elements to describe the properties just listed. So, the XML to describe the task of watering flowers might look something like this:

    <Task>

    <Name>Water Flowers</Name>

    <Priority>Medium</Priority>

    <Done>No</Done>

    <Description>

    The flowers need to be watered, or else they'll die.

    </Description>

    </Task>

    As you can see, we haven't opted for anything complex. We're only making a simple to-do list.

    Go ahead and add a new XML file to the project. Name it Tasks.xml and fill it with some tasks:

    <?xml version="1.0" encoding="utf-8" ?>

    <Tasks>

    <Task>

    <Name>Water Flowers</Name>

    <Priority>Medium</Priority>

    <Done>No</Done>

    <Description>The flowers need to be watered, or else they'll die.</Description>

    </Task>

    <Task>

    <Name>Eat Breakfast</Name>

    <Priority>High</Priority>

    <Done>Yes</Done>

    <Description>It's the most important meal of the day.</Description>

    </Task>

    <Task>

    <Name>Buy More Ink</Name>

    <Priority>Low</Priority>

    <Done>No</Done>

    <Description>It'll be out eventually.</Description>

    </Task>

    </Tasks>

    By default, the XML file is a resource. This means that the file will be included in the application's resulting assembly. This isn't what we want. In order for the application to function properly, the XML file needs to exist alongside the assembly. That way, it can be modified. To fix this, select the file, and in the Properties Window, change Build Action to Content and Copy to Output Directory to Copy if newer:



    This will allow everything to work as intended.

    More Windows Scripting Articles
    More By Peyton McCullough


       · Hello, all,This is the second part of my series introducing WPF through an...
       · how do you apply the template? thanks
       · ItemTemplate="{StaticResource TaskTemplate}"
     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - 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...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek