I have a project along with main project in my solution. I want to localize the content in this xaml file in this project.
I use the ways that have been discussed here How to change UI language using resource dictionary at run time in MVVM? .
However I could not find ObjectDataProvider in any way.
<UserControl xmlns:languageHelper="clr-namespace:XX"
<UserControl.Resources>
<ObjectDataProvider x:Key="Resources" ObjectType="{x:Type languageHelper:CultureResources}" MethodName="GetResourceInstance"/>
</UserControl.Resources>
</UserControl>
and I use this code to find ObjectDataProvider but i coulnt get it through
public static ObjectDataProvider ResourceProvider
{
get
{
if (m_provider == null)
m_provider = (ObjectDataProvider)System.Windows.Application.Current.FindResource("Resources");
return m_provider;
}
}
Resources.Culture = culture;
ResourceProvider.Refresh();
It shows System.Windows.ResourceReferenceKeyNotFoundException: ''Resources' resource not found.'
Well the problem is that you are creating your ObjectDataProvider in your UserControls resources. I think you have to create that in your App.xaml file
here is an example:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ObjectDataProvider x:Key="Resources"
ObjectType="{x:Type languageHelper:CultureResources}"
MethodName="GetResourceInstance"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.