Hi,
I am trying to do the following:
1- I have a GridView that is bound to a collection of objects.
2- however, these objects do not contain the data required for display in RowDetails.
3- I use a WCF service to obtain the required data when the user clicks a row.
(Using the GridView's SelectionChanged event) and when the Async call returns with the data, I
set the template using the code:
grdMessages.RowDetailsTemplate = (DataTemplate)this.LayoutRoot.Resources["TextMessageDetailsTemplate"]; <DataTemplate x:Key="TextMessageDetailsTemplate"> <templates:TextMessageDetailsTemplate /> </DataTemplate> 5- I created a Preoperty to hold the data inside the UserControl used as a template:
public partial class TextMessageDetailsTemplate : UserControl { private TextMessageSummary textMessageDetails; public TextMessageSummary TextMessageDetails { get { return textMessageDetails; } set { textMessageDetails = value; /* Set the values of the controls inside the template using the data in this property, like: lblMessageTitle = value.textMessageDetails.Title */ } } public TextMessageDetailsTemplate() { InitializeComponent(); } } 6- I then used a resource to hold this property and set it for the template,
so the resource defined in step 4 becomes:
<templateData:TextMessageSummary x:Key="textMessageSummary" /> <DataTemplate x:Key="TextMessageDetailsTemplate"> <templates:TextMessageDetailsTemplate TextMessageDetails="{StaticResource textMessageSummary}" /> </DataTemplate>
7- What I expected to happen here is that when selection changes a request for the Details data will be sent. When the request is back, the returned data is filled in the resource named "textMessageSummary" that is used to fill the property "TextMessageDetails" of the DetailsTemplate.
Then after that when I set the RowDetailTemplate, the template control will have its "TextMessageDetails" property filled with the required data and since the setter of this property fills the data in the required fields, then the template will show with the correct data.
8- However, what happens is that the first time I click a row, the data shows correctly, but after that, every click shows the data of the previously clicked row.
So, when I click the row "Message1" the data shows up correctly in the details if this was my first click on the grid, but if I click "Message2" row now, I'll get the details of "Message1" and if I click "Message3" row after that I'll get the "Message2" details in it.
9- What I think is happening is that the template is getting its property filled before the call to the WCF service is completed. So when the event "SelectionChanged" is fired, it is too late to set the data that will be displayed in the template.
10- I know this is a bit confusing.. but is there a way to do this?
