Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public override string ToString()
new GalleryPageFactory(() => new StepperCoreGalleryPage(), "Stepper Gallery"),
new GalleryPageFactory(() => new SwitchCoreGalleryPage(), "Switch Gallery"),
new GalleryPageFactory(() => new SwipeViewCoreGalleryPage(), "SwipeView Gallery"),
new GalleryPageFactory(() => new TimePickerControlPage(), "Time Picker Feature Matrix"),
new GalleryPageFactory(() => new TimePickerCoreGalleryPage(), "Time Picker Gallery"),
new GalleryPageFactory(() => new WebViewCoreGalleryPage(), "WebView Gallery"),
new GalleryPageFactory(() => new SliderControlPage(), "Slider Feature Matrix"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Maui.Controls.Sample"
x:Class="Maui.Controls.Sample.TimePickerControlMainPage"
x:DataType="local:TimePickerViewModel"
Title="TimePickerControlPage">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Options"
Clicked="NavigateToOptionsPage_Clicked"
AutomationId="Options"/>
</ContentPage.ToolbarItems>

<Grid RowDefinitions="*,Auto,Auto,Auto"
ColumnDefinitions="0.5*,0.5*">
<Grid x:Name="TimePickerGrid"
Grid.Row="0"
Grid.ColumnSpan="2"
VerticalOptions="Center">
<TimePicker AutomationId="TimePickerControl"
CharacterSpacing="{Binding CharacterSpacing}"
FlowDirection="{Binding FlowDirection}"
Format="{Binding Format}"
FontAttributes="{Binding FontAttributes}"
FontFamily="{Binding FontFamily}"
FontSize="{Binding FontSize}"
IsEnabled="{Binding IsEnabled}"
IsVisible="{Binding IsVisible}"
Shadow="{Binding Shadow}"
Time="{Binding Time}"
TimeSelected="TimePicker_TimeSelected"
TextColor="{Binding TextColor}"/>
</Grid>

<Label Grid.Row="1"
Grid.Column="0"
HorizontalOptions="Center"
Text="New Time: "/>
<Label Grid.Row="1"
Grid.Column="1"
x:Name="NewTimeSelectedLabel"
AutomationId="NewTimeSelectedLabel"/>

<Label Grid.Row="2"
Grid.Column="0"
HorizontalOptions="Center"
Text="Old Time: "/>
<Label Grid.Row="2"
Grid.Column="1"
x:Name="OldTimeSelectedLabel"
AutomationId="OldTimeSelectedLabel"/>

<Label Grid.Row="3"
Grid.Column="0"
HorizontalOptions="Center"
Text="Culture Format Display:"/>
<Label Grid.Row="3"
Grid.Column="1"
x:Name="CultureFormatLabel"
AutomationId="CultureFormatLabel"
Margin="0,0,0,50"/>
</Grid>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using System.Globalization;
using System.Threading;

namespace Maui.Controls.Sample;

public class TimePickerControlPage : NavigationPage
{
private TimePickerViewModel _viewModel;

public TimePickerControlPage()
{
_viewModel = new TimePickerViewModel();
PushAsync(new TimePickerControlMainPage(_viewModel));
}
}

public partial class TimePickerControlMainPage : ContentPage
{
private TimePickerViewModel _viewModel;

public TimePickerControlMainPage(TimePickerViewModel viewModel)
{
InitializeComponent();
_viewModel = viewModel;
BindingContext = _viewModel;

// Display initial culture formatting information
DisplayCultureSpecificTime(_viewModel.Time, _viewModel.Culture);
}

protected override void OnAppearing()
{
base.OnAppearing();
// Refresh culture display when returning to the page
DisplayCultureSpecificTime(_viewModel.Time, _viewModel.Culture);
}

private async void NavigateToOptionsPage_Clicked(object sender, EventArgs e)
{
// Reset culture to default when navigating to options page
_viewModel.Culture = System.Globalization.CultureInfo.CurrentCulture;

BindingContext = _viewModel = new TimePickerViewModel();
ReInitializeTimePicker();
await Navigation.PushAsync(new TimePickerOptionsPage(_viewModel));
}

private void ReInitializeTimePicker()
{
TimePickerGrid.Children.Clear();
var timePicker = new TimePicker
{
AutomationId = "TimePickerControl"
};
timePicker.SetBinding(TimePicker.CharacterSpacingProperty, new Binding(nameof(TimePickerViewModel.CharacterSpacing)));
timePicker.SetBinding(TimePicker.FlowDirectionProperty, new Binding(nameof(TimePickerViewModel.FlowDirection)));
timePicker.SetBinding(TimePicker.FormatProperty, new Binding(nameof(TimePickerViewModel.Format)));
timePicker.SetBinding(TimePicker.FontAttributesProperty, new Binding(nameof(TimePickerViewModel.FontAttributes)));
timePicker.SetBinding(TimePicker.FontFamilyProperty, new Binding(nameof(TimePickerViewModel.FontFamily)));
timePicker.SetBinding(TimePicker.FontSizeProperty, new Binding(nameof(TimePickerViewModel.FontSize)));
timePicker.SetBinding(TimePicker.IsEnabledProperty, new Binding(nameof(TimePickerViewModel.IsEnabled)));
timePicker.SetBinding(TimePicker.IsVisibleProperty, new Binding(nameof(TimePickerViewModel.IsVisible)));
timePicker.SetBinding(TimePicker.ShadowProperty, new Binding(nameof(TimePickerViewModel.Shadow)));
timePicker.SetBinding(TimePicker.TimeProperty, new Binding(nameof(TimePickerViewModel.Time)));
timePicker.TimeSelected += TimePicker_TimeSelected;
timePicker.SetBinding(TimePicker.TextColorProperty, new Binding(nameof(TimePickerViewModel.TextColor)));

// Add property changed handlers for culture/time updates
timePicker.PropertyChanged += (s, e) =>
{
if (e.PropertyName == nameof(TimePicker.Time))
{
DisplayCultureSpecificTime(timePicker.Time, _viewModel.Culture);
}
};
_viewModel.PropertyChanged += (s, e) =>
{
if (e.PropertyName == nameof(TimePickerViewModel.Culture))
{
DisplayCultureSpecificTime(timePicker.Time, _viewModel.Culture);
}
};

TimePickerGrid.Children.Add(timePicker);
}

private void DisplayCultureSpecificTime(TimeSpan time, CultureInfo culture)
{
if (culture != null)
{
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;

CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
}
CultureFormatLabel.Text = $"Culture: {culture?.Name}, Time: {DateTime.Today.Add(time).ToString("t", culture)}";
}

private void TimePicker_TimeSelected(object sender, TimeChangedEventArgs e)
{
if (e.NewTime != e.OldTime)
{
NewTimeSelectedLabel.Text = e.NewTime.ToString();
OldTimeSelectedLabel.Text = e.OldTime.ToString();
}
}
}
Loading
Loading