Skip to content

Commit 9e8f9d6

Browse files
committed
localisation on calendar
1 parent 8423b58 commit 9e8f9d6

File tree

3 files changed

+8
-24
lines changed

3 files changed

+8
-24
lines changed

MainDemo.Wpf/MainWindow.xaml.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Diagnostics;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
7-
using System.Windows;
8-
using System.Windows.Controls;
9-
using System.Windows.Controls.Primitives;
10-
using System.Windows.Data;
11-
using System.Windows.Documents;
12-
using System.Windows.Input;
13-
using System.Windows.Media;
14-
using System.Windows.Media.Imaging;
15-
using System.Windows.Navigation;
16-
using System.Windows.Shapes;
17-
using MaterialDesignColors.WpfExample.Domain;
1+
using System.Windows;
182

193
namespace MaterialDesignColors.WpfExample
204
{

MaterialDesignThemes.Wpf/MaterialDateDisplay.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,17 @@ public bool IsDayInFirstComponent
112112
private set { SetValue(IsDayInFirstComponentPropertyKey, value); }
113113
}
114114

115-
115+
//FrameworkElement.LanguageProperty.OverrideMetadata(typeof (Calendar), (PropertyMetadata) new FrameworkPropertyMetadata(new PropertyChangedCallback(Calendar.OnLanguageChanged)));
116116
private void UpdateComponents()
117117
{
118-
var dateTimeFormatInfo = CultureInfo.CurrentCulture.GetDateFormat();
118+
var dateTimeFormatInfo = CultureInfo.CurrentUICulture.GetDateFormat();
119119

120120
foreach (var component in dateTimeFormatInfo.ShortDatePattern.Split(new[] {dateTimeFormatInfo.DateSeparator},
121121
StringSplitOptions.RemoveEmptyEntries).Select((s, index) => new {code = s.ToLower()[0], index}))
122122
{
123123
if (component.index == 0)
124124
IsDayInFirstComponent = component.code == 'd';
125-
_setters[component.index](DisplayDate.ToString(_formats[component.code]).ToUpper());
125+
_setters[component.index](DisplayDate.ToString(_formats[component.code], CultureInfo.CurrentUICulture).ToUpper());
126126
}
127127
}
128128

@@ -161,7 +161,6 @@ internal static DateTimeFormatInfo GetDateFormat(CultureInfo culture)
161161
}
162162
}
163163

164-
165164
if (foundCal == null)
166165
{
167166
// if there are no GregorianCalendars in the OptionalCalendars list, use the invariant dtfi

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Calendar.xaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf"
4-
xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters">
4+
xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters"
5+
xmlns:globalization="clr-namespace:System.Globalization;assembly=mscorlib">
56
<Style x:Key="MaterialDesignCalendarButton" TargetType="{x:Type CalendarButton}">
67
<Setter Property="MinWidth" Value="5"/>
78
<Setter Property="MinHeight" Value="5"/>
@@ -363,7 +364,7 @@
363364
<Border Grid.ColumnSpan="3" Grid.Row="0" Background="{DynamicResource PrimaryHueDarkBrush}" CornerRadius="2 2 0 0">
364365
<TextBlock HorizontalAlignment="Center" Foreground="{DynamicResource PrimaryHueDarkForegroundBrush}" Margin="8" FontSize="14">
365366
<TextBlock.Text>
366-
<MultiBinding Mode="OneWay" StringFormat="dddd">
367+
<MultiBinding Mode="OneWay" StringFormat="dddd" ConverterCulture="{x:Static globalization:CultureInfo.CurrentCulture}" >
367368
<MultiBinding.Converter>
368369
<converters:CalendarDateCoalesceConverter />
369370
</MultiBinding.Converter>
@@ -380,7 +381,7 @@
380381
<Button x:Name="PART_PreviousButton" Grid.Row="2" Grid.Column="0" Focusable="False" HorizontalAlignment="Left" Height="36" Template="{StaticResource PreviousButtonTemplate}" Width="32"
381382
Margin="40 0 0 0" Foreground="{TemplateBinding Foreground}" />
382383
<TextBlock HorizontalAlignment="Center" Margin="8" FontSize="14" Grid.Row="2" Grid.Column="1" FontWeight="SemiBold" VerticalAlignment="Center"
383-
Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Calendar}}, Path=DisplayDate, StringFormat=MMMM yyyy}" />
384+
Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Calendar}}, Path=DisplayDate, ConverterCulture={x:Static globalization:CultureInfo.CurrentCulture}, StringFormat=MMMM yyyy}" />
384385
<Button x:Name="PART_NextButton" Grid.Row="2" Grid.Column="2" Focusable="False" HorizontalAlignment="Right" Height="36" Template="{StaticResource NextButtonTemplate}" Width="32"
385386
Margin="0 0 40 0" Foreground="{TemplateBinding Foreground}" />
386387
<Grid x:Name="PART_MonthView" Grid.ColumnSpan="3" HorizontalAlignment="Center" Margin="6,-1,6,6" Grid.Row="3" Visibility="Visible">

0 commit comments

Comments
 (0)