CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Apr 2011

    [WPF] XML Binding

    I have an XML file structured this way:
        <vol name="10"/>    
        <Keys name="key1" value="1" />
        <Keys name="key2" value="2" />
        <Keys name="key3" value="3" />
        <Keys name="key4" value="4" />
    I get no difficulties binding to <Settings> tag, as well as tags contained into it (color:red)
    I get no difficulties to bind the <System> tag into a list box (color:yellow).....but I don't know how to bind to tags into <topplayed>(color:blue).
    How to populate a listbox with all <topplayed> elements of the currently selected <System>?
    <Window x:Class="MainWindow"
        Title="MainWindow" Height="721" Width="525" Background="#FF4E4E64">
        <Grid Name="Grid1">
                <XmlDataProvider x:Name="SystemData" Source="C:\Users\Portable\Desktop\taper\WpfApplication1\Resources\Systems2.xml" XPath="Emulators" />
                <DataTemplate x:Key="Resource1">
                    <Label Content="{Binding XPath=@name}"/>
                <DataTemplate x:Key="Resource2">
                    <Label Content="{Binding XPath=@value}"/>
                <DataTemplate x:Key="Resource3">
                    <Label Content="{Binding XPath=Name}"/>
                <DataTemplate x:Key="Resource4">
                    <Label Content="{Binding XPath=Top}"/>
            <TextBox Text="{Binding XPath=Settings/Volume}" Height="30" HorizontalAlignment="Left" Margin="12,12,0,0" Name="TextBox5" VerticalAlignment="Top" Width="196" />
            <ListBox ItemsSource="{Binding XPath=Settings/Keys}" ItemTemplate="{StaticResource Resource1}" IsSynchronizedWithCurrentItem="True" Height="92" HorizontalAlignment="Left" Margin="12,48,0,0" Name="ListBox1" VerticalAlignment="Top" Width="196" />
            <ListBox ItemsSource="{Binding XPath=Settings/Keys}" ItemTemplate="{StaticResource Resource2}" Height="92" HorizontalAlignment="Left" IsSynchronizedWithCurrentItem="True" Margin="214,48,0,0" Name="ListBox2" VerticalAlignment="Top" Width="196" />
            <ListBox ItemsSource="{Binding XPath=System}" ItemTemplate="{StaticResource Resource3}" IsSynchronizedWithCurrentItem="True" Height="104" HorizontalAlignment="Left" Margin="12,185,0,0" Name="ListBox3" VerticalAlignment="Top" Width="196" />
            <ListBox ItemsSource="{Binding XPath=System/topplayed}" ItemTemplate="{StaticResource Resource4}" Height="74" HorizontalAlignment="Left" Margin="12,295,0,0" Name="ListBox4" VerticalAlignment="Top" Width="196" />
    Thank you very much!!
    Last edited by Jayme65; September 19th, 2012 at 11:36 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.