Question About CslaDataProvider ob Page.xaml

Question About CslaDataProvider ob Page.xaml

Old forum URL: forums.lhotka.net/forums/t/7896.aspx


Jav posted on Wednesday, October 28, 2009

Now that my object graph is being fetched just fine, I am not seeing the data being displayed in my page.

I know for sure that the data is being fetched when the page opens, and also when I call Refresh from a Button_Click.

I have a StackPanel with two TextBlocks and the DataContext set up thus:
DataContext="{Binding Source={StaticResource frameData}, Path=Data}"

The Text property of one of the TextBlocks is:
="{Binding DefaultSpecialtyName, Mode=OneWay}"

DefaultSpecialtyName field is in the Root object. I know that this field is populated by examining it as it is leaving DataAccess module. But the TextBlock shows empty.

I assume the Data in CslaDataProvider points to the root object. I will need to access the entire object graph which is about 5 deep. Do I use:

RootObject.Category.Subcategory etc. when {Binding } to controls

Thanks
Javed

RockfordLhotka replied on Wednesday, October 28, 2009

It sounds like you are doing the right thing, but clearly something isn't set up right.

Yes, in Silverlight you should set the datacontext to the Data property of the data provider control. That gets you to the root object.

To get to child objects, I typically change the datacontext of sub-regions (Grid or StackPanel controls) to point to the child property off the current datacontext.

Suppose my root is a SalesOrder object, and my form is bound to it like this:

<Grid DataContext="{Binding Source={StaticResource OrderProvider}, Path=Data}">

Then inside that grid I could have another container control like this:

<Grid DataContext="{Binding Path=LineItems}">

Now everything in this second Grid has a datacontext of the LineItems collection off the sales order.

Jav replied on Wednesday, October 28, 2009

Thanks Rocky.

Since posting the above message, I have taken a look at the InventoryDemo, specifically to see how the child objects were handled.

The object graph that I am working with is to be used to actually create the UI, not to display/edit the data. I can't say that I can see my way clear to the end, but InventoryDemo example looked interesting.

Right now I am reading all the tables into a dataset and using DataRelations to populate all the objects in the object graph. With the heirarchy right now being 5 deep, likely to get deeper quickly, using DataReaders will be cumbersome. Ultimately I will probably cache the dataset and create just the objects that I need based on user interaction.

Javed

Jav replied on Saturday, October 31, 2009

I have now attached a complete zipped Solution that illustrates the problem. I am posting it here because I don't know if it is a bug or just me.

javed

I tried uploading the zipped file (size: 6.41 MB) three time, but i didn't work.
Can be downloaded from above url.

Jav replied on Friday, October 30, 2009

I have now whittled my MainPage.xaml code down to a couple of TextBlocks, the code of entire page is attached. One TextBlock has static text ("Test Page"), the other should show the value of DefaultName field.

The code in DataPortal_Fetch is:

private void DataPortal_Fetch()
{
this.DefaultName = "MyDefaultName";
}

The breakpoint in this method shows that the code is being executed, but nothing shows up in the MainPage.

What could I be doing wrong?

Javed

RockfordLhotka replied on Saturday, October 31, 2009

You have a couple basic problems.

First, you aren't using a managed backing field. You must either use a managed backing field or you must override OnGetState() and OnSetState() to manually serialize your private backing field values.

Second, you didn't link the core class implementation to the Silverlight class library. So your property is only declared on the .NET side, not the SL side.

Jav replied on Saturday, October 31, 2009

Thank you.

Copyright (c) Marimer LLC