Only show hollow stars in editing mode

This commit is contained in:
Michael Bucari-Tovo 2022-12-31 10:33:18 -07:00
parent 05ac5c63e1
commit b4838d364e
3 changed files with 10 additions and 8 deletions

View File

@ -15,7 +15,7 @@
</Style> </Style>
</Grid.Styles> </Grid.Styles>
<TextBlock IsVisible="false" Grid.Column="0" Grid.Row="0" Name="tblockOverall" Text="Overall:" /> <TextBlock Grid.Column="0" Grid.Row="0" Name="tblockOverall" Text="Overall:" />
<TextBlock Grid.Column="0" Grid.Row="1" Name="tblockPerform" Text="Perform:" /> <TextBlock Grid.Column="0" Grid.Row="1" Name="tblockPerform" Text="Perform:" />
<TextBlock Grid.Column="0" Grid.Row="2" Name="tblockStory" Text="Story:" /> <TextBlock Grid.Column="0" Grid.Row="2" Name="tblockStory" Text="Story:" />

View File

@ -13,7 +13,7 @@ namespace LibationAvalonia.Controls
public static readonly StyledProperty<Rating> RatingProperty = public static readonly StyledProperty<Rating> RatingProperty =
AvaloniaProperty.Register<MyRatingCellEditor, Rating>(nameof(Rating)); AvaloniaProperty.Register<MyRatingCellEditor, Rating>(nameof(Rating));
public bool AllRatingsVisible { get; set; } public bool IsEditingMode { get; set; }
public Rating Rating public Rating Rating
{ {
get { return GetValue(RatingProperty); } get { return GetValue(RatingProperty); }
@ -30,19 +30,21 @@ namespace LibationAvalonia.Controls
{ {
if (change.Property.Name == nameof(Rating) && Rating is not null) if (change.Property.Name == nameof(Rating) && Rating is not null)
{ {
var blankValue = IsEditingMode ? HOLLOW_STAR : string.Empty;
int rating = 0; int rating = 0;
foreach (TextBlock star in panelOverall.Children) foreach (TextBlock star in panelOverall.Children)
star.Tag = star.Text = Rating.OverallRating > rating++ ? SOLID_STAR : HOLLOW_STAR; star.Tag = star.Text = Rating.OverallRating > rating++ ? SOLID_STAR : blankValue;
rating = 0; rating = 0;
foreach (TextBlock star in panelPerform.Children) foreach (TextBlock star in panelPerform.Children)
star.Tag = star.Text = Rating.PerformanceRating > rating++ ? SOLID_STAR : HOLLOW_STAR; star.Tag = star.Text = Rating.PerformanceRating > rating++ ? SOLID_STAR : blankValue;
rating = 0; rating = 0;
foreach (TextBlock star in panelStory.Children) foreach (TextBlock star in panelStory.Children)
star.Tag = star.Text = Rating.StoryRating > rating++ ? SOLID_STAR : HOLLOW_STAR; star.Tag = star.Text = Rating.StoryRating > rating++ ? SOLID_STAR : blankValue;
SetVisible(AllRatingsVisible); SetVisible(IsEditingMode);
} }
base.OnPropertyChanged(change); base.OnPropertyChanged(change);
} }

View File

@ -23,7 +23,7 @@ namespace LibationAvalonia.Controls
Name = "CellMyRatingDisplay", Name = "CellMyRatingDisplay",
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Left, HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Left,
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center, VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
AllRatingsVisible = false, IsEditingMode = false,
Margin = new Thickness(3), Margin = new Thickness(3),
IsEnabled = false IsEnabled = false
}; };
@ -42,7 +42,7 @@ namespace LibationAvalonia.Controls
Name = "CellMyRatingCellEditor", Name = "CellMyRatingCellEditor",
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Left, HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Left,
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center, VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
AllRatingsVisible = true, IsEditingMode = true,
Margin = new Thickness(3) Margin = new Thickness(3)
}; };