Hello @Benoit Hoffman ,
no example shows how to actually consumes those parameters in your Blazor component
You could refer to the Component parameters part in this doc : https://learn.microsoft.com/en-us/aspnet/core/blazor/components/?view=aspnetcore-6.0#component-parameters, and check Binding with component parameters
If you add the Parameters
for your RootComponent
, try to find the Main. razor
file, then add the Parameter
, refer to the following code :
Set Parameters in MainPage
(set the RootComponent
name in Xaml <RootComponent x:Name="RootComponent"....>
)
public MainPage()
{
InitializeComponent();
RootComponent.Parameters = new Dictionary<string, object> { { "MyPara", "222" } };
// or RootComponent.Parameters = new Dictionary<string, object> { ["MyPara"]= "111" };
}
Add Parameter attribute in Main. razor
@code {
[Parameter]
public string MyPara { get; set; }
}
Display this Parameter for testing
<Router AppAssembly="@typeof(Main).Assembly">
<Found Context="routeData">
......
<h1>@MyPara</h1>
</Found>
......
</Router>
------UPDATE------
We can't change parameters after setting them, because it only works on initialization. Form the source code, we can see that parameters is copied to ParameterView
by WebViewManager
on initialization. And we can check the WebViewManager source code, it only allows get
and init
method.
Best Regards,
Wenyan Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.