Click here to Skip to main content
15,894,539 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a created a simple application in WPF.but, there is a problem that is facing. Problem is that i have created two pages i.e. Homepage.xaml and ExpenseReportPage.xaml. There is a listbox in Homepage.xaml in which some users names are displayed binding with XML. and when user select any user from listbox, ExpenseReportPage.xaml opens and all details about that selected user. Details are displayed in listbox on ExpenseReportPage.xaml. There are two listboxes on second page. but, one of them displays details, another not displays. Please help me. I have used this code page by page:.....

HomePage.xaml:
XML
<grid name="Grid1">
        <grid.resources>
            
            <!--Expense Report Data-->
            <XmlDataProvider x:Key="ExpenseDataSource" XPath="Expenses">
                <x:xdata xmlns:x="#unknown">
                    <expenses xmlns="">
                        <person name="Rahul" department="IT">
                            <expense expensetype="Lunch" expenseamount="40" />
                            <expense expensetype="Transportation" expenseamount="100" />
                            <expense expensetype="BrakeFast" expenseamount="30" />
                            <expense expensetype="Entertainment" expenseamount="150" />
                        </person>
                        <person name="Mannu" department="IT">
                            <expense expensetype="Lunch" expenseamount="30" />
                            <expense expensetype="Transportation" expenseamount="50" />
                            <expense expensetype="BrakeFast" expenseamount="10" />
                            <expense expensetype="Entertainment" expenseamount="100" />
                        </person>
                        <person name="Madhu" department="Computers">
                            <expense expensetype="Lunch" expenseamount="50" />
                            <expense expensetype="Transportation" expenseamount="70" />
                            <expense expensetype="BrakeFast" expenseamount="20" />
                            <expense expensetype="Entertainment" expenseamount="70" />
                        </person>
                        <person name="Abhishek" department="Management">
                            <expense expensetype="Lunch" expenseamount="50" />
                            <expense expensetype="Transportation" expenseamount="60" />
                            <expense expensetype="BrakeFast" expenseamount="25" />
                            <expense expensetype="Entertainment" expenseamount="200" />
                        </person>
                        <person name="Jai" department="Maths">
                            <expense expensetype="Lunch" expenseamount="45" />
                            <expense expensetype="Transportation" expenseamount="170" />
                            <expense expensetype="BrakeFast" expenseamount="40" />
                            <expense expensetype="Entertainment" expenseamount="250" />
                        </person>
                    </expenses>
                </x:xdata>
            </XmlDataProvider>
            
            <!--Name Item Template-->
            <datatemplate x:key="nameItemTemplate" xmlns:x="#unknown">
                <Label Content="{Binding XPath=@Name}" ></Label>
            </datatemplate>
            
        </grid.resources>
        
        <grid.columndefinitions>
            <columndefinition width="294" />
            <columndefinition />
        </grid.columndefinitions>
        <grid.rowdefinitions>
            <rowdefinition height="Auto" />
            <rowdefinition />
        </grid.rowdefinitions>
        
        <dockpanel grid.column="0" grid.row="0" grid.columnspan="2">
            <canvas dockpanel.dock="Left" width="230" height="100"></canvas>
        </dockpanel>
        
        <Label FontFamily="Verdana" FontSize="18" FontWeight="Bold" Foreground="#FF0066CC" Height="32" Margin="67,23,64,0" VerticalAlignment="Top" Grid.ColumnSpan="2">View Expense Report</Label>
        
        <grid margin="10" grid.column="0" grid.row="2">
            <grid.columndefinitions>
                <columndefinition />       
            </grid.columndefinitions>
            <grid.rowdefinitions>
                <rowdefinition height="Auto" />
                <rowdefinition />
                <rowdefinition height="Auto" />
            </grid.rowdefinitions>
            
            <!--People List-->
            <border grid.column="0" grid.row="0" height="35" padding="5" removed="#4E87D4">
                <Label VerticalAlignment="Center" Foreground="White">NAMES</Label>
            </border>
            <listbox name="peopleListBox" grid.column="0" grid.row="1">
                     ItemsSource="{Binding Source={StaticResource ExpenseDataSource},XPath=Person}" 
                     ItemTemplate="{StaticResource nameItemTemplate}">                
            </listbox>br mode="hold" />H>
                        
            <Button Name="viewdetails" Grid.Column="0" Margin="0,10,0,0" Grid.Row="2" Height="25" Width="130" Background="DarkOliveGreen" Foreground="White" FontSize="14" Click="view_Click" >VIEW</Button>
        </grid>    
    </grid>


HomePage.Xaml.cs:
C#
public void view_Click(object sender, EventArgs e)
        {
            ExpenseReportPage objExp = new ExpenseReportPage(this.peopleListBox.SelectedItem);
            objExp.Show();
            this.Hide();
        }


ExpenseReportPage.xaml:
XML
<grid>
        <grid.background>
            <ImageBrush ImageSource="sky.jpg"></ImageBrush>
        </grid.background>
        <grid.columndefinitions>
            <columndefinition width="90*" />
            <columndefinition width="172*" />
        </grid.columndefinitions>
        <grid.rowdefinitions>
            <rowdefinition height="100" />
            <rowdefinition />
        </grid.rowdefinitions>
        <stackpanel grid.column="1" grid.row="0" height="25" width="Auto">
            <Label FontWeight="Bold" Foreground="Teal" FontSize="15">Expense Report For:</Label>
        </stackpanel>
        <grid grid.column="1" grid.row="1">
            
            <grid.columndefinitions>
                <columndefinition />
                <columndefinition />
            </grid.columndefinitions>
            <grid.rowdefinitions>                
                <rowdefinition height="25" />
                <rowdefinition height="15" />
                <rowdefinition height="10*" />
                <rowdefinition height="106*" />
            </grid.rowdefinitions>
                        
            <Label Foreground="Teal" FontWeight="Bold" FontSize="12" Width="50" HorizontalAlignment="Left">Name:</Label>
            <Label Content="{Binding XPath=@Name}" Foreground="Teal" FontWeight="Bold" FontSize="12" Margin="92,0,76.95,0" Grid.ColumnSpan="2"></Label>
            
            <Label Grid.Row="1" Foreground="Teal" Grid.ColumnSpan="2" FontWeight="Bold" FontSize="12" HorizontalAlignment="Left" Grid.RowSpan="2">Department:</Label>
            <Label Content="{Binding XPath=@Department}" Grid.Row="1" Foreground="Teal" Grid.ColumnSpan="2" FontWeight="Bold" FontSize="12" Grid.RowSpan="2" Margin="92,0,76.95,0"></Label>
            
            <grid grid.row="3" margin="0,0,5,5">
                <grid.resources>
                    <datatemplate x:key="typeItemTemplate" xmlns:x="#unknown">
                        <Label Content="{Binding XPath=@ExpenseType}"/>                        
                    </datatemplate>                    
                </grid.resources>                
                
                <grid.columndefinitions>
                    <columndefinition />
                    <columndefinition />
                </grid.columndefinitions>
                <grid.rowdefinitions>
                    <rowdefinition height="28" />
                    <rowdefinition />
                </grid.rowdefinitions>
                
                <border removed="#4E87D4" grid.row="0" grid.columnspan="2" grid.column="0">
                    <Label FontWeight="Bold" Foreground="White" FontSize="12">Expense Type:</Label>
                </border>
                <listbox grid.column="0" grid.row="1" grid.columnspan="2" itemssource="{Binding XPath=Expense}" itemtemplate="{StaticResource typeItemTemplate}"></listbox>
            </grid>
            <grid grid.column="1" grid.row="3" margin="3,0,0,5">
                <grid.resources>
                    <datatemplate x:key="amountItemTemplate" xmlns:x="#unknown">
                        <Label Content="{Binding XPath=@ExpenseAmount}"/>
                    </datatemplate>
                </grid.resources>
                
                <grid.columndefinitions>
                    <columndefinition />
                    <columndefinition />
                </grid.columndefinitions>
                <grid.rowdefinitions>
                    <rowdefinition height="28" />
                    <rowdefinition />
                </grid.rowdefinitions>
                
                <border removed="#4E87D4" grid.row="0" grid.columnspan="2" grid.column="0">
                    <Label FontWeight="Bold" Foreground="White" FontSize="12">Amount:</Label>
                </border>
                <listbox grid.column="0" grid.row="1" grid.columnspan="2" itemssource="{Binding XPath=@Expense}" itemtemplate="{StaticResource amountItemTemplate}"></listbox>
            </grid>
        </grid>
    </grid>


ExpenseReportPage.Xaml.cs:

C#
public partial class ExpenseReportPage : Window
    {
        public ExpenseReportPage(object data)
        {
            InitializeComponent();
            this.DataContext = data;
        }
    }


please help me.
Posted
Updated 20-Jun-12 23:06pm
v3

1 solution

actually in the second listbox, there is a binding problem. the correction is :

XML
" <listbox itemssource="{Binding XPath=Expense}" itemtemplate="{StaticResource amountItemTemplate}"></listbox> " 


Regards Rahul
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900