Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rating bar completed from bottom to top #3113

Closed
JeanPhilippeLux opened this issue Feb 27, 2023 · 5 comments · Fixed by #3116
Closed

Rating bar completed from bottom to top #3113

JeanPhilippeLux opened this issue Feb 27, 2023 · 5 comments · Fixed by #3116
Labels
enhancement evaluation required Items is pending review or evaluation by the team
Milestone

Comments

@JeanPhilippeLux
Copy link

Hi,

actually, the rating bar is completed from top to bottom.

I was wandering if it's possible to have an option to complete the rating bar from bottom to right.

Thank you very much.

@JeanPhilippeLux JeanPhilippeLux added enhancement evaluation required Items is pending review or evaluation by the team labels Feb 27, 2023
@JeanPhilippeLux
Copy link
Author

I have test and the new code to change is in RatingBar.cs

Changing the "for (int i = start; i <= Max; i++)" to "for (int i = Max; i >= start; i--)" is what I want

Perhaps someone can add a property "BottomToTop" True / False and changing the for iteration ?

thank you.

private void RebuildButtons()
        {
            foreach (var ratingBarButton in _ratingButtonsInternal)
            {
                ratingBarButton.MouseMove -= RatingBarButton_MouseMove;
            }
            _ratingButtonsInternal.Clear();             // When fractional values are enabled, the first rating button represents the value Min when not selected at all and Min+1 when fully selected;
            // thus we start with the value Min+1 for the values of the rating buttons.
            int start = IsFractionalValueEnabled ? Min + 1 : Min;
            for (int i = Max; i >= start; i--)
            {
                var ratingBarButton = new RatingBarButton
                {
                    Content = i,
                    ContentTemplate = ValueItemTemplate,
                    ContentTemplateSelector = ValueItemTemplateSelector,
#pragma warning disable CS0618 // Type or member is obsolete
                    IsWithinSelectedValue = i <= Value,
#pragma warning restore CS0618 // Type or member is obsolete
                    Style = ValueItemContainerButtonStyle,
                    Value = i,
                };
                ratingBarButton.MouseMove += RatingBarButton_MouseMove;
                _ratingButtonsInternal.Add(ratingBarButton);
            }
        }

@nicolaihenriksen
Copy link
Contributor

@JeanPhilippeLux This seems like a reasonable request, however the name BottomToTop is in my opinion not ideal. The reason is that this very much expects RatingBar.Orientation="Vertical" which is not a given.

Perhaps something like InvertDirection="True" or similar would be better? Although for the horizontal orientation I doubt that this would be used (since it automatically flips to RTL layout if the Culture is one with a right-to-left layout).

@JeanPhilippeLux
Copy link
Author

Hi, "InvertDirection" is really a better name (sorry for my english, I'm french speaker).

And yes, for the horizontal display, the option is not ideal.

I have test my code on the demo and it works (just need the property to add).

JeanPhilippeLux added a commit to JeanPhilippeLux/MaterialDesignInXamlToolkit that referenced this issue Mar 1, 2023
JeanPhilippeLux added a commit to JeanPhilippeLux/MaterialDesignInXamlToolkit that referenced this issue Mar 1, 2023
@nicolaihenriksen
Copy link
Contributor

nicolaihenriksen commented Mar 1, 2023

@JeanPhilippeLux I added a PR to introduce the property. Needed a little more work than just the for loop changes. Fractional values, preview indicators, and gradient fills, also needed to respect the inverted direction.

@JeanPhilippeLux
Copy link
Author

@nicolaihenriksen just make a test but your code is better. Thank you verry much.

@Keboo Keboo added this to the 4.8.0 milestone Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement evaluation required Items is pending review or evaluation by the team
Projects
None yet
3 participants