Skip to content

Commit

Permalink
Finish DateTime pickers !!!
Browse files Browse the repository at this point in the history
  • Loading branch information
flarive committed Oct 15, 2023
1 parent 92854f0 commit da0675b
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@
<StaticResource x:Key="ToolTipBorderBrush" ResourceKey="SystemControlTransientBorderBrush" />
<Thickness x:Key="ToolTipBorderThemePadding">8,5,8,7</Thickness>

<!-- Resources for DatePicker.xaml-->
<!-- Resources for DatePicker.xaml (TO CLEAN UP !) -->
<StaticResource x:Key="DatePickerSpacerFill" ResourceKey="SystemControlForegroundBaseLowBrush" />
<StaticResource x:Key="DatePickerSpacerFillDisabled" ResourceKey="SystemControlDisabledBaseLowBrush" />
<StaticResource x:Key="DatePickerButtonBorderBrush" ResourceKey="SystemControlForegroundBaseMediumBrush" />
Expand Down Expand Up @@ -486,7 +486,7 @@
<StaticResource x:Key="DateTimePickerFlyoutButtonForegroundPointerOver" ResourceKey="SystemControlHighlightAltBaseHighBrush" />
<StaticResource x:Key="DateTimePickerFlyoutButtonForegroundPressed" ResourceKey="SystemControlHighlightAltBaseHighBrush" />

<!-- Resources for TimePicker.xaml -->
<!-- Resources for TimePicker.xaml (TO CLEAN UP !) -->
<StaticResource x:Key="TimePickerSpacerFill" ResourceKey="SystemControlForegroundBaseLowBrush" />
<StaticResource x:Key="TimePickerSpacerFillDisabled" ResourceKey="SystemControlDisabledBaseLowBrush" />
<StaticResource x:Key="TimePickerButtonBorderBrush" ResourceKey="SystemControlForegroundBaseMediumBrush" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Version>0.6.0</Version>
<Version>0.7.0</Version>
<Title>Neumorphism.Avalonia</Title>
<Authors>Eviral</Authors>
<Company>Eviral</Company>
Expand Down
53 changes: 44 additions & 9 deletions Avalonia.Themes.Neumorphism/Controls/ExtendedCalendarDatePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Avalonia.Controls.Primitives;
using Avalonia.Interactivity;
using Avalonia.Controls;
using static System.Net.Mime.MediaTypeNames;

namespace Avalonia.Themes.Neumorphism.Controls
{
Expand All @@ -20,27 +21,41 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)

if (_textBox != null)
{
_textBox.LostFocus -= _textBox_LostFocus;
_textBox.LostFocus += _textBox_LostFocus;
_textBox.Loaded -= TextBox_Loaded;
_textBox.Loaded += TextBox_Loaded;

_textBox.TextChanged -= _textBox_TextChanged;
_textBox.TextChanged += _textBox_TextChanged;
_textBox.GotFocus -= TextBox_GotFocus;
_textBox.GotFocus += TextBox_GotFocus;

_textBox.LostFocus -= TextBox_LostFocus;
_textBox.LostFocus += TextBox_LostFocus;
}

_calendar = e.NameScope.Find<Calendar>("PART_Calendar");


base.OnApplyTemplate(e);
}

private void _textBox_TextChanged(object sender, TextChangedEventArgs e)


private void TextBox_Loaded(object sender, RoutedEventArgs e)
{
string text = ((TextBox)e.Source).Text;
if (_textBox != null)
{
if (UseFloatingWatermark)
{
_textBox.Watermark = string.Empty;
}

SetValue(TextProperty, text);
if (e != null && e.Source != null)
{
string text = ((TextBox)e.Source).Text ?? string.Empty;
SetValue(TextProperty, text);
}
}
}

private void _textBox_LostFocus(object sender, RoutedEventArgs e)
private void TextBox_LostFocus(object sender, RoutedEventArgs e)
{
if (_textBox != null)
{
Expand All @@ -53,12 +68,32 @@ private void _textBox_LostFocus(object sender, RoutedEventArgs e)
// clear invalid text entries
_textBox.Text = string.Empty;
}
else
{
SetValue(SelectedDateProperty, d.Value);
}
}
else
{
SetValue(TextProperty, string.Empty);
SetValue(SelectedDateProperty, null);
}

if (UseFloatingWatermark)
{
_textBox.Watermark = string.Empty;
}
}
}

private void TextBox_GotFocus(object sender, RoutedEventArgs e)
{
if (_textBox != null)
{
if (UseFloatingWatermark)
{
_textBox.Watermark = Watermark;
}
}
}

Expand Down
5 changes: 2 additions & 3 deletions Avalonia.Themes.Neumorphism/Controls/ExtendedTimePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -609,14 +609,13 @@ private void SetSelectedTime()
{
try
{
string template = "HH:mm";
string template = "H:mm";

if (ClockIdentifier == "12HourClock")
{
template = "hh:mm tt";
template = "h:mm tt";
}


DateTime dt;
if (DateTime.TryParseExact(text.ToUpper(), template, CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
{
Expand Down
22 changes: 6 additions & 16 deletions Avalonia.Themes.Neumorphism/Themes/CalendarDatePicker.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@


<ControlTheme x:Key="{x:Type CalendarDatePicker}" TargetType="CalendarDatePicker">
<Setter Property="Template">
<ControlTemplate>
<TextBlock Text="Please use ExtendedCalendarDatePicker instead of CalendarDatePicker"/>
</ControlTemplate>
</Setter>
</ControlTheme>


Expand Down Expand Up @@ -182,8 +187,7 @@
<!-- Disabled State -->
<Style Selector="^:disabled">
<Style Selector="^ /template/ Border#PART_RootBorder">
<Setter Property="Background" Value="{DynamicResource CalendarDatePickerBackgroundDisabled}" />
<Setter Property="BorderBrush" Value="{DynamicResource CalendarDatePickerBorderBrushDisabled}" />
<Setter Property="Opacity" Value="0.5" />
</Style>

<Style Selector="^ /template/ Button#PART_Button">
Expand Down Expand Up @@ -237,20 +241,6 @@
<Setter Property="MaxWidth" Value="{TemplateBinding Width}" />
</Style>







<!--<Style Selector="^:focus-within:empty /template/ TextBlock#watermark, ^:empty /template/ TextBlock#watermark">
<Setter Property="IsVisible" Value="True" />
</Style>-->

<!--<Style Selector="^:focus-within:not(:empty) /template/ TextBlock#watermark, ^:not(:empty) /template/ TextBlock#watermark">
<Setter Property="IsVisible" Value="False" />
</Style>-->

<Style Selector="^ /template/ TextBlock#floatingWatermark">
<Setter Property="Foreground" Value="{DynamicResource ThemeAccentBrush}" />
</Style>
Expand Down
Loading

0 comments on commit da0675b

Please sign in to comment.