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