For localization I\'m using the Resource-file (.resx files) functionality in .NET, but I\'m wondering if there\'s a smart way to databind the various localization properties
Here is how I do it.
WPF:
Create a resource file and in the same assembly create a class that has a public constructor. Make sure the resource file is marked public.
In your xaml file - add a reference to this location in the namespaces
xmlns:res="clr-namespace:MyProject.StringResources"
For your text property use the following binding
TextProperty="{x:Static res:ResourceFileName.ResourceKey}"
Silverlight:
Follow steps 1 & 2 above and then add the resource file as a Resource in either your user control or in an application level resource:
<res:ResourceFileName x:Key="resourcesLabels"/>
For your text property use the following binding:
TextProperty="{Binding ResourceKey, Source={StaticResource resourceLabels}}"
Very similar to what Geek proposed, but even a bit easier I think:
Create a class in the same assembly, which inherits the resources file and exposes a public constructor, then use this class instead.
public class ResourcesProxy : Properties.Resources
{
/// <summary>
/// resolves the problem of internal constructor in resources.designer.cs
/// in conjunction with xaml usage
/// </summary>
public ResourcesProxy() : base()
{
}
}