Finished Settings page
This commit is contained in:
24
WorkTime.Mobile/Pages/Components/SettingComponent.xaml
Normal file
24
WorkTime.Mobile/Pages/Components/SettingComponent.xaml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:components="clr-namespace:WorkTime.Mobile.Pages.Components"
|
||||
x:Class="WorkTime.Mobile.Pages.Components.SettingComponent"
|
||||
x:DataType="components:SettingComponent"
|
||||
x:Name="Component">
|
||||
<Grid ColumnDefinitions="*,Auto,80" ColumnSpacing="5">
|
||||
<Label Text="{Binding Title, Source={x:Reference Component}}"
|
||||
VerticalTextAlignment="Center"
|
||||
Grid.Column="0"/>
|
||||
|
||||
<Entry Placeholder="{Binding Placeholder, Source={x:Reference Component}}"
|
||||
Keyboard="Numeric"
|
||||
Grid.Column="1"
|
||||
TextChanged="OnValueChanged"
|
||||
x:Name="EntryField"/>
|
||||
|
||||
<Label Text="{Binding Unit, Source={x:Reference Component}}"
|
||||
VerticalTextAlignment="Center"
|
||||
Grid.Column="2"/>
|
||||
</Grid>
|
||||
</ContentView>
|
||||
59
WorkTime.Mobile/Pages/Components/SettingComponent.xaml.cs
Normal file
59
WorkTime.Mobile/Pages/Components/SettingComponent.xaml.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
namespace WorkTime.Mobile.Pages.Components;
|
||||
|
||||
public partial class SettingComponent : ContentView {
|
||||
public static readonly BindableProperty TitleProperty =
|
||||
BindableProperty.Create(nameof(Title), typeof(string), typeof(SettingComponent), string.Empty);
|
||||
|
||||
public static readonly BindableProperty UnitProperty =
|
||||
BindableProperty.Create(nameof(Unit), typeof(string), typeof(SettingComponent), string.Empty);
|
||||
|
||||
public static readonly BindableProperty PlaceholderProperty =
|
||||
BindableProperty.Create(nameof(Placeholder), typeof(string), typeof(SettingComponent), string.Empty);
|
||||
|
||||
public static readonly BindableProperty ValueProperty =
|
||||
BindableProperty.Create(nameof(Value), typeof(TimeSpan), typeof(SettingComponent), TimeSpan.Zero,
|
||||
BindingMode.TwoWay);
|
||||
|
||||
public string Title {
|
||||
get => (string)GetValue(TitleProperty);
|
||||
set => SetValue(TitleProperty, value);
|
||||
}
|
||||
|
||||
public string Unit {
|
||||
get => (string)GetValue(UnitProperty);
|
||||
set => SetValue(UnitProperty, value);
|
||||
}
|
||||
|
||||
public string Placeholder {
|
||||
get => (string)GetValue(PlaceholderProperty);
|
||||
set => SetValue(PlaceholderProperty, value);
|
||||
}
|
||||
|
||||
public TimeSpan Value {
|
||||
get => (TimeSpan)GetValue(ValueProperty);
|
||||
set => SetValue(ValueProperty, value);
|
||||
}
|
||||
|
||||
public SettingComponent() {
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void OnValueChanged(object? sender, TextChangedEventArgs e) {
|
||||
if (!int.TryParse(e.NewTextValue, out var number)) return;
|
||||
|
||||
switch (Unit) {
|
||||
case "Stunden":
|
||||
case "Uhr":
|
||||
Value = TimeSpan.FromHours(number);
|
||||
break;
|
||||
|
||||
case "Minuten":
|
||||
Value = TimeSpan.FromMinutes(number);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearInput() {
|
||||
Content.FindByName<Entry>(nameof(EntryField)).Text = string.Empty;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user