views:

624

answers:

1

Hi Girls and Guys!

I'm just about to start a new project of mine and am currently evaluating some techniques for localization, modularity etc.

I have (at least in my opinion) a pretty good approach to localization but now I struggle to find a good solution for databinding.

I want to bind values of textfields etc. (UIElements in general) to a specific method in the DataContext of the form. The method looks like this:

public void GetValue(string name)

where name is a "path" in the form of "node/subnode/subsubnode". I thought about using a ValueConverter for the binding and this worked out pretty good till now.

My binding expression looks like that:

{Binding Path=Localization, Converter={StaticResource LocalizationConverter}, ConverterParameter=PrismBreak/Shell.xaml/New}

I think that this binding expression although doing its job is kinda blown up to use for every single UIElement. So I thought if it was possible to define a default ValueConverter for a certain type (--> whenever that type is bound to somewhere that ValueConverter is used).

Is that possible in WPF?

If it's not possible is there any other good way to bind to a method with dynamic parameters?

Thanks in advance and best regards,

Chris

+3  A: 

The prescribed way of doing localization for WPF, is to create localized BAML in satellite assemblies; this is achieved by adding the x:Uid attached property to elements you wished to be localized. There is a nice WPF Globalization and Localization section on MSDN describing the techniques.

Another approach I would suggest would be to create a static 'Localization Dictionary' type, and to implement ICustomTypeDescriptor, to redirect incoming property binds to strings in your dictionary. You could end up doing something like this:

<Button Content="
    {Binding Source={x:Static local:MyStaticType.Localization}, 
             Path=HelloButtonTitle}" />

And you could continue to leverage existing technologies such as RESX + Satellite assemblies.

Phil Price
I googled a bit and now found a explanation for how to implement ICustomTypeDescriptor with custom properties and now it's working! Thanks for the idea!
chrischu
In case anybody's interested: http://msdn.microsoft.com/en-us/magazine/cc163816.aspx helped me out a lot.
chrischu