Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How does binding xpath=... work to wire up data from a source data page to the next page? (wpf FW 4.0)

$
0
0

I have been working on a WPF walkthrough tutorial at

http://msdn.microsoft.com/en-us/library/ms752299.aspx

I don't understand how the ExpenseReportPage reads data from the ExpenseItHome page. The source data (xml file) page has XPath="Expenses"  while the page that contains the datagrid which displays this source data uses -- binding XPath="Expense" --.  How is the data connection made?  Is there codebehind underneath it?  or is it all in the xaml?

--Here is the sample source data from ExpenseItHome page
--------------------------------------------------

<Page x:Class="ExpesneIt.ExpenseItHome"
...
 Title="ExpenseIt - Home">

    <Grid Margin="10,0,10,10">

        <Grid.Resources>         

            <!-- Expense Report Data -->
            <XmlDataProvider x:Key="ExpenseDataSource" XPath="Expenses">
                <x:XData>
                    <Expenses xmlns="">
                        <Person Name="Mike" Department="Legal">
                            <Expense ExpenseType="Lunch" ExpenseAmount="50" />
                            <Expense ExpenseType="Transportation" ExpenseAmount="50" />
                        </Person>
                        <Person Name="Lisa" Department="Marketing">
                            <Expense ExpenseType="Document printing" ExpenseAmount="50"/>
                            <Expense ExpenseType="Gift" ExpenseAmount="125" />
                        </Person>
                        <Person Name="John" Department="Engineering">
                            <Expense ExpenseType="Magazine subscription" ExpenseAmount="50"/>
                            <Expense ExpenseType="New machine" ExpenseAmount="600" />
                            <Expense ExpenseType="Software" ExpenseAmount="500" />
                        </Person>
                        <Person Name="Mary" Department="Finance">
                            <Expense ExpenseType="Dinner" ExpenseAmount="100" />
                        </Person>
                    </Expenses>
                </x:XData>
            </XmlDataProvider>

<!-- Name item template -->
<DataTemplate x:Key="nameItemTemplate">
    <Label Content="{Binding XPath=@Name}"/>
</DataTemplate>

...

--------------------------------------------------
--and here is the ExpenseReportPage. 


<Page x:Class="ExpesneIt.ExpenseReportPage"
...
 Title="ExpenseIt - View Expense">

    <Grid>

        <!--Templates to display expense report data-->
        <Grid.Resources>
            <!-- Reason item template -->
            <DataTemplate x:Key="typeItemTemplate">
                <Label Content="{BindingXPath=@ExpenseType}"/>
            </DataTemplate>
            <!-- Amount item template -->
            <DataTemplate x:Key="amountItemTemplate">
                <Label Content="{BindingXPath=@ExpenseAmount}"/>
            </DataTemplate>
        </Grid.Resources>

...

    <!-- Expense type and Amount table -->
    <DataGrid ItemsSource="{Binding XPath=Expense}" ColumnHeaderStyle="{StaticResource columnHeaderStyle}" AutoGenerateColumns="False" RowHeaderWidth="0" >
      <DataGrid.Columns>
           <DataGridTextColumn Header="ExpenseType" Binding="{BindingXPath=@ExpenseType}"  />
           <DataGridTextColumn Header="Amount" Binding="{BindingXPath=@ExpenseAmount}" />
      </DataGrid.Columns>
   </DataGrid>
...

-----------------------------------------------------

Thanks in advance for any explanations


Rich P



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>