Skip to content

Commit

Permalink
Update Sample App for .NET 8
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCodeTraveler committed Nov 7, 2023
1 parent c81e55a commit 939a671
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CommunityToolkit.Maui.Alerts;
using CommunityToolkit.Maui.Behaviors;
using CommunityToolkit.Maui.Sample.ViewModels.Behaviors;

namespace CommunityToolkit.Maui.Sample.Pages.Behaviors;
Expand All @@ -11,14 +12,15 @@ public NumericValidationBehaviorPage(NumericValidationBehaviorViewModel numericV
InitializeComponent();
}

#if !DEBUG
void SetEntryValue(object? sender, EventArgs e)
{
#else
async void SetEntryValue(object? sender, EventArgs e)
{
await Toast.Make($"The app will crash because {nameof(Options.SetShouldSuppressExceptionsInBehaviors)} is false", Core.ToastDuration.Long).Show();
#endif
var toastVisibilityTimeSpan = TimeSpan.FromSeconds(5);
var cts = new CancellationTokenSource(toastVisibilityTimeSpan);

await Toast.Make($"The app will crash because `null` is an invalid value for {nameof(NumericValidationBehavior)}.\nOptionally, {nameof(Options)}.{nameof(Options.SetShouldSuppressExceptionsInBehaviors)} can be set to true", Core.ToastDuration.Long).Show(cts.Token);

await Task.Delay(toastVisibilityTimeSpan, cts.Token);

SafeEntry.Text = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,18 @@

<Label Text="The SelectAllTextBehavior is an effect that will select all text in an Entry / Editor when it becomes focused. Useful applications for this effect would be custom url address bars, a copy paste button etc." />

<Label
FontAttributes="Bold"
Text="Entry"
TextColor="{StaticResource DarkLabelTextColor}" />


<Label FontAttributes="Italic" Text="Entry without the effect, when focused no text will be selected" />
<Label FontAttributes="Bold" Text="Entry without the Behavior"/>
<Label FontAttributes="Italic" Text="When focused no text will be selected" />
<Border BackgroundColor="{StaticResource SoftBorderBackgroundColor}" >
<Entry
BackgroundColor="{StaticResource PrimaryColor}"
PlaceholderColor="{StaticResource DarkLabelPlaceholderColor}"
Text="https://github.com/CommunityToolkit/Maui/"
TextColor="{StaticResource DarkLabelTextColor}" />
</Border>

<Label FontAttributes="Italic" Text="Entry with the effect, when focused all text will be selected" />

<Label FontAttributes="Bold" Text="Entry with the Behavior"/>
<Label FontAttributes="Italic" Text="When focused all text will be selected" />
<Border BackgroundColor="{StaticResource SoftBorderBackgroundColor}" >
<Entry
BackgroundColor="{StaticResource PrimaryColor}"
Expand All @@ -47,12 +43,8 @@
</Entry>
</Border>

<Label
FontAttributes="Bold"
Text="Editor"
TextColor="{StaticResource DarkLabelTextColor}" />

<Label FontAttributes="Italic" Text="Editor without the effect, when focused no text will be selected" />
<Label FontAttributes="Bold" Text="Editor without the Behavior" />
<Label FontAttributes="Italic" Text="When focused no text will be selected" />
<Border BackgroundColor="{StaticResource SoftBorderBackgroundColor}" >
<Editor PlaceholderColor="{StaticResource DarkLabelPlaceholderColor}"
TextColor="{StaticResource DarkLabelTextColor}"
Expand All @@ -64,7 +56,8 @@
</Editor>
</Border>

<Label FontAttributes="Italic" Text="Editor with the effect, when focused all text will be selected" />
<Label FontAttributes="Bold" Text="Editor with the Behavior" />
<Label FontAttributes="Italic" Text="When focused all text will be selected" />
<Border BackgroundColor="{StaticResource SoftBorderBackgroundColor}" >
<Editor PlaceholderColor="{StaticResource DarkLabelPlaceholderColor}"
TextColor="{StaticResource DarkLabelTextColor}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<ContentPage.Resources>
<ResourceDictionary>
<mct:ListToStringConverter x:Key="ListToStringConverter" Separator=", " />
<mct:ListToStringConverter x:Key="ListToStringConverter" Separator=" " />
</ResourceDictionary>
</ContentPage.Resources>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<!-- The All Condition Type -->
<Label Text="The All Condition Type"
Style="{StaticResource label_section_header}"
Style="{StaticResource label_section_title}"
Margin="0, 8, 0, 0"
Grid.Row="1"
Grid.ColumnSpan="2" />
Expand Down Expand Up @@ -72,7 +72,7 @@

<!-- The Any Condition Type -->
<Label Text="The Any Condition Type"
Style="{StaticResource label_section_header}"
Style="{StaticResource label_section_title}"
Margin="0, 8, 0, 0"
Grid.Row="6"
Grid.ColumnSpan="2" />
Expand Down Expand Up @@ -116,7 +116,7 @@

<!-- The Greater Than Condition Type -->
<Label Text="The Greater Than Condition Type"
Style="{StaticResource label_section_header}"
Style="{StaticResource label_section_title}"
Margin="0, 8, 0, 0"
Grid.Row="11"
Grid.ColumnSpan="2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
CornerRadius="32,0,0,32"
HeightRequest="128"
WidthRequest="128"
SemanticProperties.Description="GravatarImageSourse used with AvatarView.">
SemanticProperties.Description="GravatarImageSource used with AvatarView.">
<mct:AvatarView.Stroke>
<LinearGradientBrush EndPoint="0,1">
<GradientStop Offset="0.1" Color="Blue" />
Expand All @@ -115,19 +115,16 @@
</mct:AvatarView>
<Label x:Name="LabelEmail" Text="Email:" />
<Entry
SemanticProperties.Description="{x:Reference LabelEmail}"
Keyboard="Email"
SemanticProperties.Hint="Enter your own gravatar registered email address"
Text="{Binding Email}" />
<Label x:Name="LabelDefaultImage" Text="Default Image:" />
<Picker
SemanticProperties.Description="{x:Reference LabelDefaultImage}"
ItemsSource="{Binding DefaultGravatarItems}"
SelectedItem="{Binding DefaultGravatarSelected}"
SemanticProperties.Hint="A default image is displayed if there is no image associated with the requested email hash." />
<Label x:Name="LabelEnableCache" Text="Enable cache:" />
<Switch
SemanticProperties.Description="{x:Reference LabelEnableCache}"
IsToggled="{Binding EnableCache}"
SemanticProperties.Hint="Defines whether image caching is enabled. The default value of this property is: True" />
<Label
Expand All @@ -143,11 +140,10 @@
</Label.FormattedText>
</Label>
<Slider
SemanticProperties.Description="{x:Reference LabelCacheValidity}"
IsEnabled="{Binding EnableCache}"
Maximum="365"
Minimum="1"
SemanticProperties.Hint="Specify how long the image will be stored locally for. The default of this property is 1 day."
SemanticProperties.Hint="Specify how long the image will be stored locally. The default of this property is 1 day."
Value="{Binding CacheValidityInDays}" />
</VerticalStackLayout>
</ScrollView>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public int MaximumDecimalPlaces

/// <inheritdoc/>
protected override string? Decorate(string? value)
=> base.Decorate(value)?.ToString()?.Trim();
=> base.Decorate(value)?.Trim();

/// <inheritdoc/>
protected override ValueTask<bool> ValidateAsync(string? value, CancellationToken token)
Expand All @@ -83,17 +83,17 @@ protected override ValueTask<bool> ValidateAsync(string? value, CancellationToke
return new ValueTask<bool>(false);
}

var decimalDelimeterIndex = value.IndexOf(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
var hasDecimalDelimeter = decimalDelimeterIndex >= 0;
var decimalDelimiterIndex = value.IndexOf(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
var hasDecimalDelimiter = decimalDelimiterIndex >= 0;

// If MaximumDecimalPlaces equals zero, ".5" or "14." should be considered as invalid inputs.
if (hasDecimalDelimeter && MaximumDecimalPlaces == 0)
if (hasDecimalDelimiter && MaximumDecimalPlaces == 0)
{
return new ValueTask<bool>(false);
}

var decimalPlaces = hasDecimalDelimeter
? value.Substring(decimalDelimeterIndex + 1, value.Length - decimalDelimeterIndex - 1).Length
var decimalPlaces = hasDecimalDelimiter
? value.Substring(decimalDelimiterIndex + 1, value.Length - decimalDelimiterIndex - 1).Length
: 0;

return new ValueTask<bool>(decimalPlaces >= MinimumDecimalPlaces && decimalPlaces <= MaximumDecimalPlaces);
Expand Down

0 comments on commit 939a671

Please sign in to comment.