Skip to content

Commit

Permalink
crash with grid view #81
Browse files Browse the repository at this point in the history
  • Loading branch information
insomniachi committed Jan 20, 2024
1 parent 4f662d7 commit 3801bc0
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions Totoro.WinUI/UserControls/RatingPicker.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace Totoro.WinUI.UserControls;

public sealed partial class RatingPicker : UserControl
{
private readonly string[] _ratingNames = new string[]
{
private readonly string[] _ratingNames =
[
"(0) - No Score",
"(1) - Appalling",
"(2) - Horring",
Expand All @@ -19,7 +19,7 @@ public sealed partial class RatingPicker : UserControl
"(8) - Very Good",
"(9) - Great",
"(10) - Masterpiece"
};
];

public AnimeModel Anime
{
Expand Down Expand Up @@ -77,6 +77,12 @@ public MenuFlyout CreateFlyout(AnimeModel anime)
}

var score = anime?.Tracking?.Score ?? 0;
if (score > 10)
{
Visibility = Visibility.Collapsed;
return null;
}

var flyout = new MenuFlyout();
for (int i = 0; i < _ratingNames.Length; i++)
{
Expand All @@ -99,8 +105,17 @@ private void StackPanel_Tapped(object sender, Microsoft.UI.Xaml.Input.TappedRout

private void StackPanel_Loaded(object sender, RoutedEventArgs e)
{
var flyout = (MenuFlyout)FlyoutBase.GetAttachedFlyout(sender as StackPanel);
if(FlyoutBase.GetAttachedFlyout(sender as StackPanel) is not MenuFlyout flyout)
{
return;
}

var score = Anime?.Tracking?.Score ?? 0;
if(score > 10)
{
return;
}

((RadioMenuFlyoutItem)flyout.Items[score]).IsChecked = true;
}
}

0 comments on commit 3801bc0

Please sign in to comment.