Binding labels to BO property names

Binding labels to BO property names

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


Devman posted on Monday, March 15, 2010

Hi,

Im currently looking at localizing my BO PropertyInfo FriendlyNames and I'd like to bind my control labels to these static localized values. Ive tried something along the following lines but had no joy;

<Label Content = "{Binding BO.MyPropertyProperty.FriendlyName}"/>

Is this possible, am I way off with this approach?

Regards

David

 

Devman replied on Thursday, March 18, 2010

Just bumping this post. Surely this must be possible Big Smile

James Thomas replied on Thursday, March 18, 2010

I'm not sure whether you're using WPF or Silverlight and as I'm only using Silverlight this might not work elsewhere, but here's a bit of copy and paste from my code:

<TextBox x:Name="TextBoxSetName" Grid.Row="0" Grid.Column="1" Text="{Binding Path=SetName, Mode=TwoWay}" Margin="6,6,6,6"></TextBox>

Just set the datacontext of the Grid (for example) to your business object and away you go. ('SetName' is a property in my BO).

Devman replied on Friday, March 19, 2010

Thanks for the reply James,but I think you have misunderstood the problem.

I dont need to bind textboxes to property values in my BO.

When creating a BO we need to create property infos for each property ie;

 

 

static PropertyInfo<string> NameProperty = RegisterProperty(new PropertyInfo<string>("Name", PropertyNames.Name));

In this example I would I want to bind a labels content to NameProperty.FriendlyName. The value of this is the resource PropertyNames.Name.  I could just bind the label content to the resource PropertyNames.Name, but if I move my resources I then have to update two references to the resource instead of one.

Regards

David

 

 

RockfordLhotka replied on Friday, March 19, 2010

In CSLA 4 we'll be picking up the friendly name value from the DataAnnotations display name attribute if it has been used on the property. If that hasn't been used we'll fall back to the older display property from System.ComponentModel.

In any case, if you explicitly provide a friendly name to RegisterProperty() we'll use that.

But the preferred way to provide a friendly name will now be via the DataAnnotations display name property, which allows hard-coded display names, or resource-based display names that can be localized.

Devman replied on Friday, March 19, 2010

Hi Rocky,

We may well use DataAnnotations in future, however currently we are using RegisterProperty and Static PropertyInfos.I had a binding syntax error. Heres the correct binding.

<

 

 

Label Content="{Binding Source={x:Static Domain:BoType.DescriptionProperty}, Path=FriendlyName}" />

Thanks for your time!

Regards

David

 

Copyright (c) Marimer LLC