View Full Version : Localization And Globalization in MVVM
powerboy2988
سه شنبه 17 مرداد 1391, 17:11 عصر
سلام
شما از چه روش هایی برای پیاده سازی Localization And Globalization in MVVM استفاده کردید؟
ممنون.
Amir Oveisi
چهارشنبه 18 مرداد 1391, 08:51 صبح
روشی که در امضای بنده هست رو ببینید. من خودم از این روش استفاده می کنم. برای آوردنش روی mvvm هم کار خاصی نیاز نیست انجام بدید. قسمت های مربوط به این که چه زبانی انتخاب بشه و چجوری از فایل های DLL محتویات زبان جدید رو LOAD کنید میتونید تو view model بنویسید. بقیه هم که resource اند و مقداری کد تو app.cs داره.
powerboy2988
چهارشنبه 18 مرداد 1391, 10:43 صبح
قبل از اینکه با MVVM و Prism کار کنم.. از همین روش استفاده می کردم...
اما حالا مشکلم اینکه وقتی می خواد LoadComponent کنه این exception رو میده :
An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll
نمی دونم چرا unhandled exception میده.... در حالی که تو try catch گذاشتمش!!
اینه :
public void LoadCulture(CultureAssemblyModel culture)
{
try
{
//setting current culture of applpications main thread to selected one.
System.Threading.Thread.CurrentThread.CurrentUICul ture = new System.Globalization.CultureInfo(culture.Culture);
System.Threading.Thread.CurrentThread.CurrentCultu re = new System.Globalization.CultureInfo(culture.Culture);
//creating a FileInfo object represents .dll file of selected cultur
FileInfo assemblyFile = new FileInfo("languages\\" + culture.Name);
//loading .dll into memory as a .net assembly
var assembly = Assembly.LoadFile(assemblyFile.FullName);
//getting .dll file name
var assemblyName = assemblyFile.Name.Substring(0, assemblyFile.Name.LastIndexOf("."));
//creating string represents structure of a pack uri (something like this: /{myassemblyname;component/myresourcefile.xaml}
string packUri = string.Format(@"/{0};component/{1}", assemblyName, culture.XamlFileName);
//creating a pack uri
Uri uri = new Uri(packUri, UriKind.Relative);
//now we have created a pack uri that represents a resource object in loaded assembly
//and its time to load that as a resource dictionary (do u remember that we had resource dictionary in culture assemblies? don't u?)
var dic = Application.LoadComponent(uri) as ResourceDictionary;
dic.Source = uri;
//here we will remove current merged dictionaries in our resource dictionary and add recently-loaded resource dictionary as e merged dictionary
var mergedDics = this.Resources.MergedDictionaries;
if (mergedDics.Count > 0)
mergedDics.Clear();
mergedDics.Add(dic);
}
catch (StackOverflowException StackOverflowException)
{
Console.WriteLine("StackOverflowException Error : " + StackOverflowException.Message);
Console.WriteLine("StackOverflowException StackTrace : " + StackOverflowException.StackTrace);
}catch (Exception exception)
{
Console.WriteLine("Error : " + exception.Message);
Console.WriteLine("StackTrace : " + exception.StackTrace);
}
}
powerboy2988
چهارشنبه 18 مرداد 1391, 17:27 عصر
تونستم حلش کنم... با روشی که گفتید
واقعا ممنون از راهنماییتون
فقط مونده Globalization ...
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.