您可以明確設置Silverlight應用程序的UICulture和Culture,以確保無論用戶區域設置如何,UICulture和Culture都將得到修復。
這可以通過兩種方式
1集的對象標籤上的瀏覽器
<param name="uiculture" value="it-IT" />
<param name="culture" value="it-IT" />
2-在Application_Startup
Thread.CurrentThread.CurrentCulture = new CultureInfo("it-IT");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("it-IT");
更新設置線程的文化來實現:上述內容在使用StringFormat時似乎不起作用。鑑於此,我會恢復使用自定義值轉換器。下面是一個示例
MainPage.xaml中
<UserControl x:Class="SLLocalizationTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SLLocalizationTest"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<UserControl.Resources>
<local:DoubleToStringConverter x:Key="DoubleToStringConverter" />
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel>
<TextBlock Text="{Binding Price, Converter={StaticResource DoubleToStringConverter}, ConverterParameter=C2 }"/>
<TextBlock Text="{Binding Price, Converter={StaticResource DoubleToStringConverter} }"/>
</StackPanel>
</Grid>
</UserControl>
MainPage.xaml.cs中
using System;
using System.Windows;
using System.Windows.Controls;
using System.Globalization;
using System.Windows.Data;
namespace SLLocalizationTest
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
DataContext = this;
}
public double Price
{
get { return 12353.23; }
}
}
public class DoubleToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
if (value is double)
{
return ((double)value).ToString((string)parameter);
}
return value.ToString();
}
public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
即使在沒有安裝意大利語的環境? – ccen 2010-12-23 15:45:42