Windows Scripting
  Home arrow Windows Scripting arrow Page 3 - 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  
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

Adding Controls to an Application with WPF
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    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 - Databinding


    (Page 3 of 4 )

    Next, the XML file needs to be wired into the ListBox. The first step is to make the data in the XML file accessible to the application by creating an XmlDataProvider. This can be done in the application's XAML, so no code is required. The XmlDataProvider is an example of a resource, which we can define once and use in multiple places. Resource definitions go in the appropriate Resources section. The XML file only needs to be used inside of Window1, and so we need to first create an object.Resources element as a child of Window1's Window element:

    <Window.Resources>


    </Window.Resources>

    Then, the XmlDataProvider needs to be created within this section:

    <XmlDataProvider x:Key="tasks" Source="Tasks.xml" XPath="Tasks/Task" />

    There are three attributes that we define. The first is x:Key, which provides the resource with a unique identifier. The second is Source, which, of course, points to the source XML file. The third is XPath, which is set to the query used to generate the collection of elements. Here, we need access to the Task elements, which are located inside of the Tasks root element.

    The next step is to hook the ListBox up to the XmlDataProvider. This is really simple to do. Replace the existing ListBox declaration with this:

    <ListBox Name="TaskListBox" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" ItemsSource="{Binding Source={StaticResource tasks}}" />

    Above, we specify the ItemsSource attribute. We connect it to the XmlDataProvider using its x:Key, tasks.

    More Windows Scripting Articles
    More By Peyton McCullough


       · Hello, all,This is the second part of my series introducing WPF through an...
     

    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 5 hosted by Hostway
    Stay green...Green IT