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

Improve the usage experience with IsInRangeConverter in XAML #1983

Merged

Conversation

GeorgeLeithead
Copy link
Contributor

@GeorgeLeithead GeorgeLeithead commented Jun 25, 2024

Description of Change

When initially written, the IsInRangeConverter used CompareConverter as a guide/basis. Since then, the CompareConverter has been changed to improve the usage experience in XAML. See #1841 for details.

This PR brings the IsInRangeConverter back into alignment with the CompareConverter, in terms of implementation.

The current use of the converter is as follows:

            <Color x:Key="LightGreen">LightGreen</Color>
            <Color x:Key="PaleVioletRed">PaleVioletRed</Color>
            <x:Double x:Key="MinValue">3.0</x:Double>
            <x:Double x:Key="MaxValue">7.0</x:Double>
            <converters:DoubleIsInRangeConverter
                x:Key="isBetweenThreeAndSevenConverter"
                FalseObject="{StaticResource PaleVioletRed}"
                MaxValue="{StaticResource MaxValue}"
                MinValue="{StaticResource MinValue}"
                TrueObject="{StaticResource LightGreen}" />

If a developer tries to write MaxValue="7", and the value for the converter is a Double, the user will not get any valid results from the converter. In XAML, the MaxValue="7" has a type of String, by default.

This PR makes it possible to define what type MaxValue and MinValue should be when inheriting from the converter, based on the value.

Converter definition

public sealed class DoubleIsInRangeConverter : IsInRangeConverter<double, Color>;

XAML Usage

            <converters:DoubleIsInRangeConverter
                x:Key="isBetweenThreeAndSevenConverter"
                FalseObject="{StaticResource PaleVioletRed}"
                MaxValue="7"
                MinValue="3"
                TrueObject="{StaticResource LightGreen}" />

I have also removed the un-used CompareValue property.

I think that this will make is easier for users to use, and eliminate any confusion about XAML defaulting to String for this control.

Linked Issues

  • Fixes #

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Documentation created or updated: https://github.com/MicrosoftDocs/CommunityToolkit/pulls

Additional information

Validate that the MinValue and MaxValue types can be converted to the valueType.
@GeorgeLeithead
Copy link
Contributor Author

Note that I would need to update the DOCs, so this should be blocked until the docs are ready.

@GeorgeLeithead
Copy link
Contributor Author

This also "Needs Discussion" label added.

Copy link
Contributor

@bijington bijington left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GeorgeLeithead thank you for this! Apologies for the delay in reviewing this. I have added a number of comments, some improving existing bits (xml docs) and others just to confirm my understanding. I like the concept.

GeorgeLeithead and others added 7 commits July 26, 2024 10:09
Co-authored-by: Shaun Lawrence <shaunrlawrence@gmail.com>
Co-authored-by: Shaun Lawrence <shaunrlawrence@gmail.com>
Co-authored-by: Shaun Lawrence <shaunrlawrence@gmail.com>
Co-authored-by: Shaun Lawrence <shaunrlawrence@gmail.com>
Removed unnecessary checks
Removed no longer used method.
Updated tests to use correct exception thrown then using incompatible TValue objects.
@VladislavAntonyuk VladislavAntonyuk added the needs discussion Discuss it on the next Monthly standup label Aug 3, 2024
bijington
bijington previously approved these changes Aug 21, 2024
Copy link
Contributor

@bijington bijington left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this @GeorgeLeithead

@brminnick
Copy link
Collaborator

brminnick commented Aug 21, 2024

Are we sure that removing the all of the BindablePropertys is a good choice?

This means that users can no longer bind to any of the following properties from the VIewModel:

  • FalseObject
  • MaxValue
  • MinValue
  • TrueObject

Personally, I'd prefer that we keep the bindable properties unless someone with more XAML knowledge can help me understand.

@bijington
Copy link
Contributor

Are we sure that removing the all of the BindablePropertys is a good choice?

This means that users can no longer bind to any of the following properties from the VIewModel:

  • FalseObject

  • MaxValue

  • MinValue

  • TrueObject

Personally, I'd prefer that we keep the bindable properties unless someone with more XAML knowledge can help me understand.

That was my initial thinking but I struggled to get input on this.

@bijington
Copy link
Contributor

Let me put them back so we can merge this in

@brminnick brminnick enabled auto-merge (squash) August 21, 2024 21:13
@GeorgeLeithead
Copy link
Contributor Author

I have some comments to make on this. Well do so tomorrow.

@brminnick brminnick merged commit f5cf4b4 into CommunityToolkit:main Aug 21, 2024
7 checks passed
@GeorgeLeithead
Copy link
Contributor Author

Um.. Ok, too late to add my 2-pennies... but...

  • The original implementation I made for IsInRangeConverter was based on the ONLY other generic converter in the toolkit CompareConverter. When it was upgraded in PR Improve the usage experience with CompareConverter in XAML #1841 , this therefore prompted me to 'do the same' to this converter. As such, the bindable properties were not present in the CompareConverter.
  • All of the samples, tests, examples in the docs AND the examples I provided in the PR details, all work and in fact it's now much easier now as it's easier to provide the TYPE.
  • Currently, I believe that no other converter in the tool kit provides any BindableProperty(s).

So, I think the big question in reality is: Should we either adhere to the same standard and NOT have bindable properties, or should we add bindable properties to all [appropriate] converters? If the former, then I don't think we should have bindable properties on this converter. If the latter, then IMO a bigger PR should be undertaken, and at the (very IMO) VERY LEAST additional Unit Tests should have been added BEFORE we approved the PR.

Thoughts? @bijington @brminnick, et all? (Should this be an open discussion on Discord, instead of against the PR?)

@bijington
Copy link
Contributor

I agree that we should consider the bigger picture on whether all or no converters should have BindableProperty's or none.

I don't agree that additional tests should have been added before this PR merged, the point that I believe is important is that the PR was removing functionality by removing the BindableProperty definitions, the last change was just to prevent this loss of functionality - this wasn't adding new functionality that needed to also be tested. Although in truth those tests should have existed which would have caught this loss of functionality but hindsight is a wonderful thing.

I completely agree with the below statement and thank you for improving it

All of the samples, tests, examples in the docs AND the examples I provided in the PR details, all work and in fact it's now much easier now as it's easier to provide the TYPE.

The above is still true with the retention of the BindableProperty's.

But to come back to the original point, I agree that we should discuss whether all or no converters should have bindable properties and we consider the risk of breaking people based on the outcome.

@GeorgeLeithead GeorgeLeithead deleted the FeatureImproveIsInRangeConverter branch September 19, 2024 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs discussion Discuss it on the next Monthly standup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants