以正确的语言获取日期

时间:2018-11-13 15:51:42

标签: c# xamarin data-binding xamarin.forms

我添加了带有日期(以天为单位,日期和月份以字母为单位)的标签,但我还需要它来显示正确的语言。

我有这个标签:

<Label Text="{Binding Date, StringFormat='{0:dd MMMM}'}"></Label>

我已经在ViewModel中找到了它:

public class EventPageViewModel : INotifyPropertyChanged
{
    private readonly INavigationService _navigationService;
    //public DelegateCommand Date { get; set; }

    public EventPageViewModel(INavigationService navigationService)
    {
        _navigationService = navigationService;
    }

    DateTime _startdate;
    public DateTime Date
    {
        get
        {
            return _startdate;
        }
        set
        {
            _startdate = value;
            RaisePropertyChanged("Date");

        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    protected void RaisePropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

我已经尝试了很多东西,但是我怎么能以某种方式添加它:

CultureInfo MyCultureInfo = new CultureInfo("se-SE");

所以用我想要的语言说十月。

非常感谢!

1 个答案:

答案 0 :(得分:0)

您没有说是否使用基于resx/resw的本地化或OS本机。...

设置默认的线程区域性:

System.Globalization.CultureInfo.DefaultThreadCurrentCulture = new System.Globalization.CultureInfo("se-SE");

在单个线程级别设置区域性。

Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("se-SE");

通过Xamarin.Forms本地化设置:

Globalizing Xamarin.Forms Code

您可以在表格级别设置文化

AppResources.Culture =  new CultureInfo("se-SE");