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

NullReferenceException thrown after adding a button handler in a GridView's CellTemplate

$
0
0

I am trying use a combination of ListBox and ListView to display my data. My data basically consists of Session class, UERecord class and UEDialog class. Their relationships are:

1 Session <---> N UERecord instances.

1 UERecord <--> N UEDialog instances.

Session class has the following properties:

- StartTime, EndTime, MNC, MCC, LAC, SC

- Children: a list of UERecord i.e. List<UERecord>

UERecord class has the following properties which I want to display:

- IMSI, IMEI,

- DialogList: a list of UEDialog instances i.e. List<UEDialog>

My desired display is something like this:

Session 1:

 Session Property 1

 Session Property 2

 Session Children List (a list of UERecords)

     - UERecord 1 and its properties  and a  <Button> to see UERecord 1 details

     - UERecord 2 and its properties  and a <Button> to see UERecord 2 details

...

Session X:

   ...

   ...

At the top level is my ListBox which I am displaying the various properties of Session using DataTemplate. For the Session's Children property, I am embedding a ListView to display it.

So the overall format looks like:

<ListBox>

  <ListBox.ItemTemplate>

      <DataTemplate>

         <StackPanel>

             <TextBox>  .... various TextBox with multiple binding to display Session's

                   properties like MCC, MNC, etc

             </TextBox>

             <ListView ItemSource="{Binding Path=Children}">

                   ... various GridViewColumn to display the UERecord's properties like IMSI, IMEI

                   <GridViewColumn.CellTemplate>

                         <DataTemplate>   <Button Tag="{Binding Path=DialogList}"

                                                          Click="btn_Click1"> See details </Button>

                         </DataTemplate>

                    </GridViewColumn.CellTemplate>

             </ListView>

         </StackPanel>

      </DataTemplate>

...

</ListBox>

Now the problem: I found out that when I add the button eventHandler (see the Bold part above), WPF will throw a NullReferenceException with Additional Info stating that "Object reference not set to an instance of an object".

If I remove this eventHandler, everything is fine (note the button is still there but have no functionality since I removed the handler).

I don't understand why should this cause a problem.  Appreciate any advice/help. 

  




Viewing all articles
Browse latest Browse all 18858

Trending Articles



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