Windows-XAML / Template10

Making Windows 10 apps great again
Apache License 2.0
1.41k stars 389 forks source link

Add ToUri() to the PathBuilder #1719

Open JerryNixon opened 4 years ago

JerryNixon commented 4 years ago

Currently has ToString() which requires:

var path = PathBuilder.Create(BackStackBehaviors.Clear, nameof(MyView)).ToString();
await NavigationService.NavigateAsync(new Uri(path, UriKind.Relative));

This works and should not be changed.

The desired ADDITIONAL syntax would be:

var path = PathBuilder.Create(BackStackBehaviors.Clear, nameof(MyView)).ToUri();
await NavigationService.NavigateAsync(path);

It will be difficult to remember the UriKind.Relative part anyway.

JerryNixon commented 4 years ago

An alternative is to allow NavigationService.NavigateAsync to accept PathBuilder as an argument. This would not only NOT require creating the Uri by the developer, but also drive them toward the type.

darenm commented 4 years ago

Once a dev creates a PathBuilder instance using this method - are they likely to do anything to it? Or does it exist solely to create a string/(or Uri) that is then passed into NavigateAsync? If the latter, then why not have the below and save the need to create another object entirely:

await NavigationService.NavigateAsync(BackStackBehaviors.Clear, nameof(MyView));
JerryNixon commented 4 years ago

You might also use the PathBuilder if you are putting a payload inside a JumpList or a Tile or inside a Toast so that you can use that payload to preload the Frame after you activate the app. I still think the best approach here is to simply allow NavigateAsync to accept PathBuilder as an argument.

var path = PathBuilder.Create(BackStackBehaviors.Clear, nameof(MyView));
await NavigationService.NavigateAsync(path, {extra in-memory parameters});

I don't see a downside to ALSO implementing ToUri() while we are in there.

JerryNixon commented 4 years ago

I wonder if a fluent API would be useful here.