WPF - Binding child forms and other queries

WPF - Binding child forms and other queries

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


tiptop posted on Tuesday, October 06, 2009

Hello

I am new to CSLA and are currently evaluating it in a prototype project with a view to using it in a proposed large project.

I have got the whole framework working fine and binding to a table to a wpf form without too many issues.

What I can't work out from the examples is how to bind a second data source to a form.

For example, I have an Employee table and I can bind this fine to the form. I also have a foreign key on this table to an Address table. LINQ Classes load the child table data fine but I can't seem to get the wpf form to bind the address fields to the address table data. I am using a second csla dataprovider in the xaml that looks like this :

ObjectType="{x:Type Mydb:Address}"
FactoryMethod="GetAddress"
IsAsynchronous="False"
IsInitialLoadEnabled="False"
DataChanged="DataChanged"
ManageObjectLifetime="True">


and binding the fields like this

DataContext="{Binding Source={StaticResource Address}}" Text="{Binding Address1, Converter={StaticResource IdentityConverter}, ValidatesOnDataErrors=True}"

It all compiles fine but the data doesn't show on the form.

The project tracker example uses a slightly different way of displaying child data and I have not been able to work out how to do it for my needs.

Any hints would be greatly appreciated.

Mark

sergeyb replied on Tuesday, October 06, 2009

If you are dealing with child's data, you do not need a separate data provider, you can just bind to a property on main provider.



Where AddressFields sits inside another layout control with data context bound to main provider and your Employee object has property called Address which has a property called Address1

Sergey Barskiy
Principal Consultant
office: 678.405.0687 | mobile: 404.388.1899

Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

-----Original Message-----
From: tiptop [mailto:cslanet@lhotka.net]
Sent: Tuesday, October 06, 2009 8:06 AM
To: Sergey Barskiy
Subject: [CSLA .NET] WPF - Binding child forms and other queries

Hello

I am new to CSLA and are currently evaluating it in a prototype project with a view to using it in a proposed large project.

I have got the whole framework working fine and binding to a table to a wpf form without too many issues.

What I can't work out from the examples is how to bind a second data source to a form.

For example, I have an Employee table and I can bind this fine to the form. I also have a foreign key on this table to an Address table. LINQ Classes load the child table data fine but I can't seem to get the wpf form to bind the address fields to the address table data. I am using a second csla dataprovider in the xaml that looks like this :

ObjectType="{x:Type Mydb:Address}"
FactoryMethod="GetAddress"
IsAsynchronous="False"
IsInitialLoadEnabled="False"
DataChanged="DataChanged"
ManageObjectLifetime="True">


and binding the fields like this

DataContext="{Binding Source={StaticResource Address}}" Text="{Binding Address1, Converter={StaticResource IdentityConverter}, ValidatesOnDataErrors=True}"

It all compiles fine but the data doesn't show on the form.

The project tracker example uses a slightly different way of displaying child data and I have not been able to work out how to do it for my needs.

Any hints would be greatly appreciated.

Mark

RockfordLhotka replied on Tuesday, October 06, 2009

That's correct. You really need a data provider for each root object, and then you can bind to child objects through the parent object's properties.

In CSLA .NET 3.8 the CslaDataProvider control supports "chaining", where a data provider's ObjectInstance property can be bound to a property of a "parent" data provider control. The reason for doing this is to support more of an MVVM model while still using the data provider control.

tiptop replied on Tuesday, October 06, 2009

Thanks for both replies. Both of those helped in solving the problem as what I needed to do was use Address.City for binding the child table / objects. I have removed the second csla data provider.

What I need to do next is work how to trigger a data changed event for the child bound fields as at the moment when I change this data, the "Save" button remains disabled.

Thanks for your help.

RockfordLhotka replied on Tuesday, October 06, 2009

If the data provider connects to your root object, and your Save button is
bound to the data provider (or an ObjectStatus bound to the data provider)
then the Save button should enable automatically when the parent/root
object's IsSavable property is true.

IsSavable will be true if the user is authorized to do the save, if the
entire object graph is valid and if any object in the object graph has been
changed.


-----Original Message-----
From: tiptop [mailto:cslanet@lhotka.net]
Sent: Tuesday, October 06, 2009 10:02 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: WPF - Binding child forms and other queries

Thanks for both replies. Both of those helped in solving the problem as what
I needed to do was use Address.City for binding the child table / objects.
I have removed the second csla data provider.

What I need to do next is work how to trigger a data changed event for the
child bound fields as at the moment when I change this data, the "Save"
button remains disabled.

Thanks for your help.


Copyright (c) Marimer LLC