Skip to content

Conversation

@michael-hawker
Copy link
Member

@michael-hawker michael-hawker commented Feb 25, 2021

Also Fixes #3671, and related to #1908

Adds a basic sample for SwitchPresenter to the sample app. Would like to do a more advanced one still though. This also fixes a small bug in the case selection logic.

Any suggestions for sample scenarios where we could switch off a strong type like an enum or some other type would be appreciated. 🙂

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Sample app changes

What is the current behavior?

Would crash if no default case provided and no matching case available.

(And no sample.)

What is the new behavior?

Control goes back to presenting nothing if no match or default is available.

  • Sample!

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
  • Pull Request has been submitted to the documentation repository instructions. Link:
  • Sample in sample app has been added / updated (for bug fixes / features)
  • New major technical changes in the toolkit have or will be added to the Wiki e.g. build changes, source generators, testing infrastructure, sample creation changes, etc...
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • Contains NO breaking changes

TO DO

  • Add an Advanced scenario to the page using TargetType
  • Address [Feature] Provide a Type MarkupExtension #3784 as well? (Think un-needed for now?) App can always do this if needed.
  • Remove listening for Child Value binding changes as complicates the control.

@ghost
Copy link

ghost commented Feb 25, 2021

Thanks michael-hawker for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌

@michael-hawker michael-hawker added this to the 7.0 milestone Feb 25, 2021
@ghost ghost requested review from Kyaa-dost, Rosuavio and azchohfi February 25, 2021 20:29
@ghost ghost added the bug 🐛 An unexpected issue that highlights incorrect behavior label Feb 25, 2021
Fix name of TargetType DependencyProperty
Add better Enum string support
…ection or case values

Can't think of scenarios where this was actually useful and added a lot of complexity.
Removing it for now for the core value the control provides and simplifies the structure.
Samples from Sample App continue to work as expected.
@michael-hawker michael-hawker force-pushed the switchpresenter-sample branch from 41225e1 to 2e3ccec Compare March 4, 2021 20:37
@michael-hawker michael-hawker marked this pull request as ready for review March 4, 2021 20:37
@michael-hawker
Copy link
Member Author

@chingucoding thanks for taking a look, I've made updates based on our discussions and simplified the logic as you suggested.

@RosarioPulella or @Kyaa-dost want to take a quick look? This is ready to go now! 🎉🎉🎉

@ghost
Copy link

ghost commented Mar 4, 2021

Hello @michael-hawker!

Because this pull request has the auto merge :zap: label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

Copy link
Member

@Sergio0694 Sergio0694 left a comment

Choose a reason for hiding this comment

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

Couple minor questions, but looks good and works great! 🎉

Comment on lines 17 to 22
/// <summary>
/// Initializes a new instance of the <see cref="CaseCollection"/> class.
/// </summary>
public CaseCollection()
{
}
Copy link
Member

Choose a reason for hiding this comment

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

Nit: this could safely be removed in theory, right?

/// An collection of <see cref="Case"/> to help with XAML interop.
/// </summary>
public class CaseCollection : IList<Case>, IEnumerable<Case> // TODO: Do we need this or can we use an ObservableCollection directly??? (Or is it useful to have it manage the registration of the child events?)
public class CaseCollection : DependencyObjectCollection
Copy link
Member

Choose a reason for hiding this comment

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

Is this not sealed on purpose?

Comment on lines +207 to +212
static object ThrowExceptionForKeyNotFound()
{
throw new InvalidOperationException("The requested enum value was not present in the provided type.");
}

return ThrowExceptionForKeyNotFound();
Copy link
Member

Choose a reason for hiding this comment

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

Ha, nice! 😄

Cat,
Dog,
Bunny,
Llama,
Copy link
Contributor

Choose a reason for hiding this comment

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

Most important change in this PR :P

ui:TextBoxExtensions.Regex="^[a-zA-Z]{6}$"
Header="Confirmation code"
PlaceholderText="6 letters" />
<TextBlock Visibility="{Binding (ui:TextBoxExtensions.IsValid), ElementName=ConfirmationCodeValidator}">Thanks for entering a valid code!</TextBlock>
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: use Text property for fast path rendering

ui:TextBoxExtensions.Regex="(^\d{10}$)|(^\d{13}$)"
Header="E-ticket number"
PlaceholderText="10 or 13 numbers" />
<TextBlock Visibility="{Binding (ui:TextBoxExtensions.IsValid), ElementName=TicketValidator}">Thanks for entering a valid code!</TextBlock>
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: same here

@ghost ghost merged commit 0feca9c into CommunityToolkit:master Mar 4, 2021
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SwitchPresenter NullReferenceException

4 participants