Skip to content

Commit

Permalink
Try to fix Native AOT app crash at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Frédéric Larivé committed Oct 11, 2023
1 parent 6e9c6ea commit df545e6
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<PackageReference Include="Avalonia.Desktop" Version="11.0.4" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.0.4" />
<PackageReference Include="Avalonia.ReactiveUI" Version="11.0.4" />
<PackageReference Include="SkiaSharp" Version="2.88.6" />
<PackageReference Include="SkiaSharp" Version="2.88.6" />
<AvaloniaResource Include="**/*.xaml" />
</ItemGroup>
<ItemGroup>
Expand Down
45 changes: 24 additions & 21 deletions Avalonia.Themes.Neumorphism/Controls/ExtendedTimePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ namespace Avalonia.Themes.Neumorphism.Controls
[TemplatePart("PART_FlyoutButton", typeof(Button))]
[TemplatePart("PART_FlyoutButtonContentGrid", typeof(Grid))]
[TemplatePart("PART_TextBox", typeof(TextBox))]
[TemplatePart("PART_HourTextBlock", typeof(TextBlock))]
[TemplatePart("PART_MinuteTextBlock", typeof(TextBlock))]
[TemplatePart("PART_PeriodTextBlock", typeof(TextBlock))]
//[TemplatePart("PART_HourTextBlock", typeof(TextBlock))]
//[TemplatePart("PART_MinuteTextBlock", typeof(TextBlock))]
//[TemplatePart("PART_PeriodTextBlock", typeof(TextBlock))]
[TemplatePart("PART_PickerPresenter", typeof(TimePickerPresenter))]
[TemplatePart("PART_Popup", typeof(Popup))]
[TemplatePart("PART_SecondColumnDivider", typeof(Rectangle))]
Expand All @@ -41,9 +41,9 @@ public class ExtendedTimePicker : TemplatedControl
private Border? _secondPickerHost;
private Border? _thirdPickerHost;
private TextBox? _textBox;
private TextBlock? _hourText;
private TextBlock? _minuteText;
private TextBlock? _periodText;
//private TextBlock? _hourText;
//private TextBlock? _minuteText;
//private TextBlock? _periodText;
private Rectangle? _firstSplitter;
private Rectangle? _secondSplitter;
private Grid? _contentGrid;
Expand Down Expand Up @@ -224,9 +224,9 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
_secondPickerHost = e.NameScope.Find<Border>("PART_SecondPickerHost");
_thirdPickerHost = e.NameScope.Find<Border>("PART_ThirdPickerHost");

_hourText = e.NameScope.Find<TextBlock>("PART_HourTextBlock");
_minuteText = e.NameScope.Find<TextBlock>("PART_MinuteTextBlock");
_periodText = e.NameScope.Find<TextBlock>("PART_PeriodTextBlock");
//_hourText = e.NameScope.Find<TextBlock>("PART_HourTextBlock");
//_minuteText = e.NameScope.Find<TextBlock>("PART_MinuteTextBlock");
//_periodText = e.NameScope.Find<TextBlock>("PART_PeriodTextBlock");

_firstSplitter = e.NameScope.Find<Rectangle>("PART_FirstColumnDivider");
_secondSplitter = e.NameScope.Find<Rectangle>("PART_SecondColumnDivider");
Expand Down Expand Up @@ -382,25 +382,23 @@ private void SetSelectedTimeText()
newTime = new TimeSpan(hr, newTime.Minutes, 0);
}

_hourText.Text = newTime.ToString("%h");
_minuteText.Text = newTime.ToString("mm");
//_hourText.Text = newTime.ToString("%h");
//_minuteText.Text = newTime.ToString("mm");
PseudoClasses.Set(":hasnotime", false);



_periodText.Text = time.Value.Hours >= 12 ? CultureInfo.CurrentCulture.DateTimeFormat.PMDesignator :
CultureInfo.CurrentCulture.DateTimeFormat.AMDesignator;
//_periodText.Text = time.Value.Hours >= 12 ? CultureInfo.CurrentCulture.DateTimeFormat.PMDesignator : CultureInfo.CurrentCulture.DateTimeFormat.AMDesignator;

_textBox.Text = TimeToString(newTime);
}
else
{
_hourText.Text = "hour";
_minuteText.Text = "minute";
//_hourText.Text = "hour";
//_minuteText.Text = "minute";
PseudoClasses.Set(":hasnotime", true);

_periodText.Text = DateTime.Now.Hour >= 12 ? CultureInfo.CurrentCulture.DateTimeFormat.PMDesignator :
CultureInfo.CurrentCulture.DateTimeFormat.AMDesignator;
//_periodText.Text = DateTime.Now.Hour >= 12 ? CultureInfo.CurrentCulture.DateTimeFormat.PMDesignator : CultureInfo.CurrentCulture.DateTimeFormat.AMDesignator;

_textBox.Text = string.Empty;
}
Expand Down Expand Up @@ -466,7 +464,7 @@ private void TextBox_GotFocus(object? sender, RoutedEventArgs e)

private void _textBox_LostFocus(object sender, RoutedEventArgs e)
{
SetTextBoxValue(_textBox.Text);
SetTextBoxValue(_textBox?.Text ?? string.Empty);
}

private void TextBox_KeyDown(object? sender, KeyEventArgs e)
Expand All @@ -483,7 +481,7 @@ private bool ProcessTimePickerKey(KeyEventArgs e)
{
case Key.Enter:
{
SetTextBoxValue(_textBox.Text);
SetTextBoxValue(_textBox?.Text ?? string.Empty);
return true;
}
case Key.Down:
Expand Down Expand Up @@ -534,7 +532,7 @@ private void OnTimeSelected(TimeSpan? addedDate, TimeSpan? removedDate)
removedItems.Add(removedDate.Value);
}

handler(this, new TimePickerSelectedValueChangedEventArgs(removedDate.Value, addedDate.Value));
handler(this, new TimePickerSelectedValueChangedEventArgs(removedDate.HasValue ? removedDate.Value : null, addedDate.HasValue ? addedDate.Value : null));
}
}

Expand Down Expand Up @@ -609,7 +607,12 @@ private void SetSelectedTime()
{
//SetWaterMarkText();
SetCurrentValue(TextProperty, string.Empty);
_textBox.Text = string.Empty;

if (_textBox != null)
{
_textBox.Text = string.Empty;
}

Clear();
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

<Border x:Name="PART_RootBorder"
CornerRadius="{TemplateBinding Height, Converter={StaticResource ControlHeightToCornerRadiusConverter}, ConverterParameter=0}"
Height="{TemplateBinding Height}"
Height="{TemplateBinding Height}"
BorderThickness="0"
BorderBrush="Transparent"
Background="{TemplateBinding Background}">
Expand Down
4 changes: 2 additions & 2 deletions Avalonia.Themes.Neumorphism/Themes/TimePicker.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@

<Grid Name="PART_Grid" ColumnDefinitions="*,Auto" Margin="0" VerticalAlignment="Center">
<!--Main container-->
<StackPanel Orientation="Horizontal">
<!--<StackPanel Orientation="Horizontal">
<TextBlock Name="PART_HourTextBlock" IsVisible="False"/>
<TextBlock Name="PART_MinuteTextBlock" IsVisible="False"/>
<TextBlock Name="PART_PeriodTextBlock" IsVisible="False"/>
</StackPanel>
</StackPanel>-->
<Panel Grid.Column="0" Name="PART_TextRoot" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<DataValidationErrors Name="DataValidation" Errors="{TemplateBinding (DataValidationErrors.Errors)}" VerticalContentAlignment="Center" VerticalAlignment="Stretch" Margin="0">
<TextBox Name="PART_TextBox"
Expand Down
4 changes: 2 additions & 2 deletions Neumorphism.Avalonia.Demo/Neumorphism.Avalonia.Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
<!--Condition below is needed to generate macOS App only.-->
<PackageReference Include="Dotnet.Bundle" Version="0.9.13" Condition="$(RuntimeIdentifier.StartsWith('osx'))" />
<PackageReference Include="Material.Icons.Avalonia" Version="2.0.1" />
<PackageReference Include="ShowMeTheXaml.Avalonia" Version="1.3.0" />
<PackageReference Include="ShowMeTheXaml.Avalonia.Generator" Version="1.3.0" />
<PackageReference Include="ShowMeTheXaml.Avalonia" Version="1.4.0" />
<PackageReference Include="ShowMeTheXaml.Avalonia.Generator" Version="1.4.0" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 5 additions & 4 deletions Neumorphism.Avalonia.Demo/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Avalonia;
using Neumorphism.Avalonia.Demo.Windows;
using System;
using System;
using System.Threading.Tasks;
using Avalonia;
using Neumorphism.Avalonia.Demo.Windows;
using ShowMeTheXaml;

namespace Neumorphism.Avalonia.Demo
Expand All @@ -18,7 +18,8 @@ public static void Main(string[] args)
//dotnet publish -c release --framework net7.0 -r win-x64
//dotnet publish -c release --framework net8.0 -r win-x64

//https://github.com/dotnet/runtime/blob/main/src/coreclr/nativeaot/docs/debugging.md
// how to debug a native aot crash :
// https://github.com/dotnet/runtime/blob/main/src/coreclr/nativeaot/docs/debugging.md



Expand Down

0 comments on commit df545e6

Please sign in to comment.