Skip to content

Commit fb387c7

Browse files
authored
Added StartPath to get/set initial BlazorWebView URL (#11942)
* Added StartPath - gets or sets the path for initial navigation when the application starts * Changed summary for StartPath * small fix * Changed the summary for StartPath * changed the summary of StartPath for WinForms and Wpf * remove public from StartPath in IBlazorWebView
1 parent 1c4c0dd commit fb387c7

16 files changed

+89
-6
lines changed

src/BlazorWebView/src/Maui/Android/BlazorWebViewHandler.Android.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private void StartWebViewCoreIfPossible()
120120
}
121121
}
122122

123-
_webviewManager.Navigate("/");
123+
_webviewManager.Navigate(VirtualView.StartPath);
124124
}
125125

126126
internal IFileProvider CreateFileProvider(string contentRootDir)

src/BlazorWebView/src/Maui/BlazorWebView.cs

+14
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ public BlazorWebView()
3030
/// </summary>
3131
public string? HostPage { get; set; }
3232

33+
/// <summary>
34+
/// Bindable property for <see cref="StartPath"/>.
35+
/// </summary>
36+
public static readonly BindableProperty StartPathProperty = BindableProperty.Create(nameof(StartPath), typeof(string), typeof(BlazorWebView), "/");
37+
38+
/// <summary>
39+
/// Gets or sets the path for initial navigation within the Blazor navigation context when the Blazor component is finished loading.
40+
/// </summary>
41+
public string StartPath
42+
{
43+
get { return (string)GetValue(StartPathProperty); }
44+
set { SetValue(StartPathProperty, value); }
45+
}
46+
3347
/// <inheritdoc cref="IBlazorWebView.RootComponents" />
3448
public RootComponentsCollection RootComponents { get; }
3549

src/BlazorWebView/src/Maui/IBlazorWebView.cs

+9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ public interface IBlazorWebView : IView
1515
/// </summary>
1616
string? HostPage { get; }
1717

18+
/// <summary>
19+
/// Gets or sets the path for initial navigation within the Blazor navigation context when the Blazor component is finished loading.
20+
/// </summary>
21+
public string StartPath
22+
{
23+
get => "/";
24+
set => throw new NotImplementedException();
25+
}
26+
1827
/// <summary>
1928
/// Gets a collection of <see cref="RootComponent"/> items.
2029
/// </summary>
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
#nullable enable
2+
Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.StartPath.get -> string!
3+
Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.StartPath.set -> void
4+
Microsoft.AspNetCore.Components.WebView.Maui.IBlazorWebView.StartPath.get -> string!
5+
Microsoft.AspNetCore.Components.WebView.Maui.IBlazorWebView.StartPath.set -> void
6+
static readonly Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.StartPathProperty -> Microsoft.Maui.Controls.BindableProperty!
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
#nullable enable
2+
Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.StartPath.get -> string!
3+
Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.StartPath.set -> void
4+
Microsoft.AspNetCore.Components.WebView.Maui.IBlazorWebView.StartPath.get -> string!
5+
Microsoft.AspNetCore.Components.WebView.Maui.IBlazorWebView.StartPath.set -> void
6+
static readonly Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.StartPathProperty -> Microsoft.Maui.Controls.BindableProperty!
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
#nullable enable
2+
Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.StartPath.get -> string!
3+
Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.StartPath.set -> void
4+
Microsoft.AspNetCore.Components.WebView.Maui.IBlazorWebView.StartPath.get -> string!
5+
Microsoft.AspNetCore.Components.WebView.Maui.IBlazorWebView.StartPath.set -> void
6+
static readonly Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.StartPathProperty -> Microsoft.Maui.Controls.BindableProperty!
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
#nullable enable
2+
Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.StartPath.get -> string!
3+
Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.StartPath.set -> void
4+
Microsoft.AspNetCore.Components.WebView.Maui.IBlazorWebView.StartPath.get -> string!
5+
Microsoft.AspNetCore.Components.WebView.Maui.IBlazorWebView.StartPath.set -> void
6+
static readonly Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.StartPathProperty -> Microsoft.Maui.Controls.BindableProperty!
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
#nullable enable
2+
Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.StartPath.get -> string!
3+
Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.StartPath.set -> void
4+
Microsoft.AspNetCore.Components.WebView.Maui.IBlazorWebView.StartPath.get -> string!
5+
Microsoft.AspNetCore.Components.WebView.Maui.IBlazorWebView.StartPath.set -> void
6+
static readonly Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.StartPathProperty -> Microsoft.Maui.Controls.BindableProperty!
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
#nullable enable
2+
Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.StartPath.get -> string!
3+
Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.StartPath.set -> void
4+
Microsoft.AspNetCore.Components.WebView.Maui.IBlazorWebView.StartPath.get -> string!
5+
Microsoft.AspNetCore.Components.WebView.Maui.IBlazorWebView.StartPath.set -> void
6+
static readonly Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView.StartPathProperty -> Microsoft.Maui.Controls.BindableProperty!

src/BlazorWebView/src/Maui/Tizen/BlazorWebViewHandler.Tizen.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ private void StartWebViewCoreIfPossible()
184184
_ = rootComponent.AddToWebViewManagerAsync(_webviewManager);
185185
}
186186
}
187-
_webviewManager.Navigate("/");
187+
_webviewManager.Navigate(VirtualView.StartPath);
188188
}
189189

190190
internal IFileProvider CreateFileProvider(string contentRootDir)

src/BlazorWebView/src/Maui/Windows/BlazorWebViewHandler.Windows.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private void StartWebViewCoreIfPossible()
8383
_ = rootComponent.AddToWebViewManagerAsync(_webviewManager);
8484
}
8585
}
86-
_webviewManager.Navigate("/");
86+
_webviewManager.Navigate(VirtualView.StartPath);
8787
}
8888

8989
internal IFileProvider CreateFileProvider(string contentRootDir)

src/BlazorWebView/src/Maui/iOS/BlazorWebViewHandler.iOS.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private void StartWebViewCoreIfPossible()
150150
}
151151
}
152152

153-
_webviewManager.Navigate("/");
153+
_webviewManager.Navigate(VirtualView.StartPath);
154154
}
155155

156156
internal IFileProvider CreateFileProvider(string contentRootDir)

src/BlazorWebView/src/WindowsForms/BlazorWebView.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ public string? HostPage
7979
}
8080
}
8181

82+
/// <summary>
83+
/// Path for initial Blazor navigation when the Blazor component is finished loading.
84+
/// </summary>
85+
[Category("Behavior")]
86+
[Description(@"Path for initial Blazor navigation when the Blazor component is finished loading.")]
87+
public string StartPath { get; set; } = "/";
88+
8289
// Learn more about these methods here: https://docs.microsoft.com/en-us/dotnet/desktop/winforms/controls/defining-default-values-with-the-shouldserialize-and-reset-methods?view=netframeworkdesktop-4.8
8390
private void ResetHostPage() => HostPage = null;
8491
private bool ShouldSerializeHostPage() => !string.IsNullOrEmpty(HostPage);
@@ -193,7 +200,7 @@ private void StartWebViewCoreIfPossible()
193200
// Since the page isn't loaded yet, this will always complete synchronously
194201
_ = rootComponent.AddToWebViewManagerAsync(_webviewManager);
195202
}
196-
_webviewManager.Navigate("/");
203+
_webviewManager.Navigate(StartPath);
197204
}
198205

199206
private void HandleRootComponentsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs eventArgs)
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
#nullable enable
2+
Microsoft.AspNetCore.Components.WebView.WindowsForms.BlazorWebView.StartPath.get -> string!
3+
Microsoft.AspNetCore.Components.WebView.WindowsForms.BlazorWebView.StartPath.set -> void

src/BlazorWebView/src/Wpf/BlazorWebView.cs

+19-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ public class BlazorWebView : Control, IAsyncDisposable
3232
ownerType: typeof(BlazorWebView),
3333
typeMetadata: new PropertyMetadata(OnHostPagePropertyChanged));
3434

35+
/// <summary>
36+
/// The backing store for the <see cref="StartPath"/> property.
37+
/// </summary>
38+
public static readonly DependencyProperty StartPathProperty = DependencyProperty.Register(
39+
name: nameof(StartPath),
40+
propertyType: typeof(string),
41+
ownerType: typeof(BlazorWebView),
42+
typeMetadata: new PropertyMetadata("/"));
43+
3544
/// <summary>
3645
/// The backing store for the <see cref="RootComponent"/> property.
3746
/// </summary>
@@ -129,6 +138,15 @@ public string HostPage
129138
set => SetValue(HostPageProperty, value);
130139
}
131140

141+
/// <summary>
142+
/// Path for initial Blazor navigation when the Blazor component is finished loading.
143+
/// </summary>
144+
public string StartPath
145+
{
146+
get => (string)GetValue(StartPathProperty);
147+
set => SetValue(StartPathProperty, value);
148+
}
149+
132150
/// <summary>
133151
/// A collection of <see cref="RootComponent"/> instances that specify the Blazor <see cref="IComponent"/> types
134152
/// to be used directly in the specified <see cref="HostPage"/>.
@@ -267,7 +285,7 @@ private void StartWebViewCoreIfPossible()
267285
// Since the page isn't loaded yet, this will always complete synchronously
268286
_ = rootComponent.AddToWebViewManagerAsync(_webviewManager);
269287
}
270-
_webviewManager.Navigate("/");
288+
_webviewManager.Navigate(StartPath);
271289
}
272290

273291
private WpfDispatcher ComponentsDispatcher { get; }
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
#nullable enable
2+
Microsoft.AspNetCore.Components.WebView.Wpf.BlazorWebView.StartPath.get -> string!
3+
Microsoft.AspNetCore.Components.WebView.Wpf.BlazorWebView.StartPath.set -> void
4+
static readonly Microsoft.AspNetCore.Components.WebView.Wpf.BlazorWebView.StartPathProperty -> System.Windows.DependencyProperty!

0 commit comments

Comments
 (0)