리소스 파일이 이미 생성되었습니다. 앱을 다시 시작한 후 언어가 현재 작동합니다.WPF 다국어 GUI Switch-on-the-fly
비행 중에 gui (리본)의 언어를 전환 할 수 있습니까?
이미 시도 : 변경 cultureinfo 및 initializecomponents 호출 작동하지 않습니다.
리소스 파일이 이미 생성되었습니다. 앱을 다시 시작한 후 언어가 현재 작동합니다.WPF 다국어 GUI Switch-on-the-fly
비행 중에 gui (리본)의 언어를 전환 할 수 있습니까?
이미 시도 : 변경 cultureinfo 및 initializecomponents 호출 작동하지 않습니다.
나는이 주제에 너무 오래 전념했다. 내가 찾은 것은 그것이 가능하다는 것이지만 약간의 노력이 필요할 것입니다. 내가 기억하는 유일한 해결책은 응용 프로그램을 종료한다는 것입니다. 그 순간에 일괄 처리가 시작되어 사용자의 응용 프로그램이 다시 시작되어 갑자기 앱이 갑자기 종료되고 사라지면 사용자가 놀라지 않을 것입니다. 앱이 다시 시작되면 모든 UI 요소를 해당 문화권으로 다시로드합니다.
변경하기 위해 내 앱을 종료하지 않아도되기 때문에이 방법을 사용하지 않았습니다. 하지만 가능합니다.
발생하는 현상은 앱에서 문화권이 변경되지만 이에 따라 컨트롤이 업데이트되지 않는다는 것입니다. 다시 시작하면이 문제가 "수정"됩니다.
희망이 조금 도움이되었습니다.
동일한 문제가 발생하여 저에게 잘 맞는 해결책을 찾았습니다. 변환기가 필요하지 않지만 코드가 필요합니다. .NET 4.5 프레임 워크가 사용됩니다.
두 불명확 일이 즉석에서 언어를 전환하기 위해 필요한 : 정적 속성에 바인딩의 또 다른 맛
사용이 <TextBlock Text="{Binding Path=(p:Resources.LocalizedString)}"/>
와 <TextBlock Text="{Binding Source={x:Static p:Resources.LocalizedString}}"/>
를 교체합니다. XAML 디자이너는 부수적으로 이러한 속성에 대해 빈 문자열을 표시합니다.
변경 알림은 리소스에서 작동하지 않습니다. 정적 바인딩을 수동으로 다음 코드에 의해 갱신되는 것을 해결하려면 :
// ... after the current culture has changed
UpdateStaticBindings(Application.Current.MainWindow, typeof(Properties.Resources), true);
/// <summary>
/// Update all properties bound to properties of the given static class.
/// Only update bindings like "{Binding Path=(namespace:staticClass.property)}".
/// Bindings like "{Binding Source={x:Static namespace:staticClass.property}}" cannot be updated.
/// </summary>
/// <param name="obj">Object that must be updated, normally the main window</param>
/// <param name="staticClass">The static class that is used as the binding source, normally Properties.Resources</param>
/// <param name="recursive">true: update all child objects too</param>
static void UpdateStaticBindings(DependencyObject obj, Type staticClass, bool recursive)
{
// Update bindings for all properties that are statically bound to
// static properties of the given static class
if (obj != null)
{
MarkupObject markupObject = MarkupWriter.GetMarkupObjectFor(obj);
if (markupObject != null)
{
foreach (MarkupProperty mp in markupObject.Properties)
{
if (mp.DependencyProperty != null)
{
BindingExpression be = BindingOperations.GetBindingExpression(obj, mp.DependencyProperty) as BindingExpression;
if (be != null)
{
// Only update bindings like "{Binding Path=(namespace:staticClass.property)}"
if (be.ParentBinding.Path.PathParameters.Count == 1)
{
MemberInfo mi = be.ParentBinding.Path.PathParameters[0] as MemberInfo;
if (mi != null && mi.DeclaringType.Equals(staticClass))
{
be.UpdateTarget();
}
}
}
}
}
}
// Iterate children, if requested
if (recursive)
{
foreach(object child in LogicalTreeHelper.GetChildren(obj))
{
UpdateStaticBindings(child as DependencyObject, staticClass, true);
}
}
}
}
모든 세부 정보를? – Troggy
현지화에 어떤 기술을 사용하고 있습니까? LocBaml? Resx 파일? 다른 것? –