Skip to content

Commit c2a725c

Browse files
committed
Examples of using the Translates property with static resources, bindings and C#.
1 parent bc4f6ff commit c2a725c

File tree

4 files changed

+24
-30
lines changed

4 files changed

+24
-30
lines changed

Maui.NullableDateTimePicker.Samples/MainPage.xaml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@
44
xmlns:local="clr-namespace:Maui.NullableDateTimePicker.Samples"
55
xmlns:ndtp="clr-namespace:Maui.NullableDateTimePicker;assembly=Maui.NullableDateTimePicker"
66
x:Class="Maui.NullableDateTimePicker.Samples.MainPage"
7+
xmlns:collections="clr-namespace:System.Collections.ObjectModel;assembly=netstandard"
78
BackgroundColor="{AppThemeBinding Light=AliceBlue, Dark=DarkGray}"
89
x:DataType="local:MainPage">
10+
<ContentPage.Resources>
11+
<ResourceDictionary>
12+
<collections:ObservableCollection x:Key="ClockTranslates" x:TypeArguments="ndtp:TranslateItem">
13+
<ndtp:TranslateItem Key="Hour" Value="Saat" />
14+
<ndtp:TranslateItem Key="Minute" Value="Dakika" />
15+
</collections:ObservableCollection>
16+
</ResourceDictionary>
17+
</ContentPage.Resources>
918
<ContentPage.ToolbarItems>
1019
<ToolbarItem Text="Modal" Command="{Binding OpenModalCommand}"/>
1120
</ContentPage.ToolbarItems>
@@ -16,6 +25,8 @@
1625
VerticalOptions="Fill">
1726
<Label Text="Maui Nullable and Clearable DateTimePicker Examples" FontSize="16" FontAttributes="Bold" VerticalOptions="Center" TextColor="Black" />
1827

28+
29+
1930
<HorizontalStackLayout VerticalOptions="Center">
2031
<Label Text="Toggle Dark Mode"
2132
FontSize="16"
@@ -37,12 +48,8 @@
3748
HorizontalOptions="Start"
3849
CornerRadius="5"
3950
Padding="5,0,5,0"
40-
SelectedDayStyle="{StaticResource SelectedDayStyle}">
41-
<ndtp:NullableDateTimePicker.Translates>
42-
<ndtp:TranslateItem Key="Hour" Value="Saat"/>
43-
<ndtp:TranslateItem Key="Minute" Value="Dakika"/>
44-
</ndtp:NullableDateTimePicker.Translates>
45-
</ndtp:NullableDateTimePicker>
51+
SelectedDayStyle="{StaticResource SelectedDayStyle}"
52+
Translates="{StaticResource ClockTranslates}" />
4653

4754
<Label Text="Date time picker control with border + popup with border and translates binding" TextColor="Black" />
4855

Maui.NullableDateTimePicker/Controls/ButtonTemplate.xaml.cs

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public ButtonTemplate()
1616
TapCommand = new Command(OnTapped);
1717
BindingContext = this;
1818
UpdateVisualState();
19-
19+
2020
}
2121

2222
public static readonly BindableProperty TextProperty =
@@ -62,29 +62,13 @@ private void UpdateVisualState()
6262
{
6363
if (Selected)
6464
{
65-
if (Application.Current.RequestedTheme == AppTheme.Dark)
66-
{
67-
OuterBorder.BackgroundColor = Colors.DimGray;
68-
InnerLabel.TextColor = Colors.White;
69-
}
70-
else
71-
{
72-
OuterBorder.BackgroundColor = Colors.Blue;
73-
InnerLabel.TextColor = Colors.White;
74-
}
65+
OuterBorder.BackgroundColor = Application.Current.RequestedTheme == AppTheme.Dark ? Colors.DimGray : Colors.Blue;
66+
InnerLabel.TextColor = Colors.White;
7567
}
7668
else
7769
{
78-
if (Application.Current.RequestedTheme == AppTheme.Dark)
79-
{
80-
OuterBorder.BackgroundColor = Colors.DarkGray;
81-
InnerLabel.TextColor = Colors.White;
82-
}
83-
else
84-
{
85-
OuterBorder.BackgroundColor = Colors.LightGray;
86-
InnerLabel.TextColor = Colors.Black;
87-
}
70+
OuterBorder.BackgroundColor = Application.Current.RequestedTheme == AppTheme.Dark ? Colors.DarkGray : Colors.LightGray;
71+
InnerLabel.TextColor = Colors.Black;
8872
}
8973
}
9074
}

Maui.NullableDateTimePicker/Controls/ClockDrawable.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,13 @@ public void Draw(ICanvas canvas, RectF dirtyRect)
6262
//clickablePoints.Add((x, y, "Hour", i));
6363

6464
// Draw the large dot
65+
canvas.FontSize = 11;
6566
canvas.FillColor = Color.FromArgb("#4f20b0");
6667
canvas.FillCircle(x, y, 3);
6768

6869
// Place the _hour12 number on the inner side of the circle
6970
canvas.FontColor = Colors.Black;
70-
canvas.FontSize = 10; // More visible font size
71+
7172
float textX = (float)((ClockRadius - 10) * Math.Cos(angle));
7273
float textY = (float)((ClockRadius - 10) * Math.Sin(angle));
7374

@@ -97,6 +98,7 @@ public void Draw(ICanvas canvas, RectF dirtyRect)
9798
//clickablePoints.Add((x, y, "Minute", i));
9899

99100
// Set color and size (large in 5 minutes)
101+
canvas.FontSize = 11;
100102
canvas.FillColor = Color.FromArgb("#4f20b0");
101103
float radius = i % 5 == 0 ? 3 : 1;
102104
canvas.FillCircle(x, y, radius);

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ More examples, please see the samples project
168168
| ShowWeekNumbers | Determines whether to display week numbers in the calendar. | false |
169169
| ToolButtonsStyle | Style of the control's tool buttons. | null |
170170
| WeekNumberStyle | Style of the week numbers in the calendar. | null |
171+
| Translates | This property is used to customize certain texts. Currently, it allows changing the text of the AM/PM buttons and the Hour/Minute group buttons in the clock view. | In 12-hour format: AM/PM, and in 24-hour format: 00–11 / 12–23, Hour/Minute |
171172

172173

173174
## Datetimepicker Input Options (If NullableDateTimePicker is used as ContentView)
@@ -234,11 +235,11 @@ on ios, android, windows, maccatalyst
234235

235236
# Changelog
236237

237-
### 3.1.2 Preview
238+
### 3.1.2
238239
- Fixed ClockView freeze when SelectedDate is null and changing hour, minute, or AM/PM. (Thanks @universaldata-eu)
239240
- Fixed the clock display issue on Windows.
240241
- Group buttons have been added instead of toggle buttons that changed AM/PM and hour/minute.
241-
- A Translates list has been added. With this, the hour,minute,AM,PM texts on the group buttons can be customized. (See examples for usage.)
242+
- A Translates property has been added. With this, the hour,minute,AM,PM texts on the group buttons can be customized. (See examples for usage.)
242243

243244
### 3.1.1
244245
- Fixed issue where item colors in SelectList were not applied correctly.

0 commit comments

Comments
 (0)