Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting culture of days of the week #29

Closed
ivanteles opened this issue Feb 22, 2022 · 8 comments
Closed

Setting culture of days of the week #29

ivanteles opened this issue Feb 22, 2022 · 8 comments
Labels
question Further information is requested

Comments

@ivanteles
Copy link

How to set the culture to pt-br so that the days of the week are in Portuguese?

@ME-MarvinE ME-MarvinE changed the title Days Week pt br Setting culture of days of the week Feb 23, 2022
@ME-MarvinE ME-MarvinE added the question Further information is requested label Feb 23, 2022
@ME-MarvinE
Copy link
Owner

The CalendarView has no built-in support for cultures. However it does expose a DayNameTemplate property which you can use to implement the Portugese text yourself.

@ME-MarvinE ME-MarvinE removed the question Further information is requested label Feb 23, 2022
@ivanteles
Copy link
Author

What kind of data should I pass?
list Days?

@ME-MarvinE
Copy link
Owner

ME-MarvinE commented Mar 3, 2022

Its a DataTemplate which gets passed a binding context of DayOfWeek from the CalendarView's DayNamesOrder property.

Basic Example:

<xc:CalendarView.DayNameTemplate>
    <DataTemplate>
        <Label Text="{Binding .}"/>
    </DataTemplate>
</xc:CalendarView.DayNameTemplate>

Whatever the process is for providing culture based text would go in there. Or you could use DataTriggers or a converter with hardcoded values.

@ivanteles
Copy link
Author

ivanteles commented Mar 3, 2022

So I made a convert, but the control doesn't pass in my convert!

<xCalendar:CalendarView.DayNameTemplate>
                    <DataTemplate>
                            <Label Text="{Binding ., Mode=TwoWay, Converter={StaticResource DayConverter}}" />
                    </DataTemplate>
                </xCalendar:CalendarView.DayNameTemplate>

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var dia = (DayOfWeek) value;
            switch (dia)
            {
                case DayOfWeek.Sunday: return "Dom";
                case DayOfWeek.Monday: return "Seg";
                case DayOfWeek.Tuesday: return "Ter";
                case DayOfWeek.Wednesday: return "Qua";
                case DayOfWeek.Thursday: return "Qui";
                case DayOfWeek.Friday: return "Sex";
                case DayOfWeek.Saturday: return "Sab";
                default: return "";
            }
        }

@ME-MarvinE
Copy link
Owner

ME-MarvinE commented Mar 3, 2022

I always thought this was optional, but it seems that if x:DataType is not set on the DataTemplate, the converter won't be called at all.

Here's the example you used but with x:DataType:

Using xmlns:System="clr-namespace:System;assembly=System.Runtime"

<xCalendar:CalendarView.DayNameTemplate>
    <DataTemplate x:DataType="{x:Type System:DayOfWeek}">
        <Label Text="{Binding ., Mode=TwoWay, Converter={StaticResource DayConverter}}" />
    </DataTemplate>
</xc:CalendarView.DayNameTemplate>

{x:Type System:DayOfWeek} can also be written as System:DayOfWeek.

Hope this fixes your issue!

@ivanteles
Copy link
Author

It was just that! Thank you!

@nandodefaria
Copy link

How to set the culture to pt-br so that the days of the week are in Portuguese?

Hi! Can you send me the files, to see how to implement it? Thanks

@ME-MarvinE
Copy link
Owner

I believe you change the value of either System.Globalization.CultureInfo.CurrentCulture or System.Globalization.CultureInfo.CurrentUICulture to the Portuguese culture. I don't remember if you need to do this before instantiating your calendar.

System.Globalization.CultureInfo.CurrentCulture = new CultureInfo("pt-br");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants