Skip to content

[Blazor] Migrating property from one-way to two way binding #49187

Closed Answered by SteveSandersonMS
daniel-p-tech asked this question in Q&A
Discussion options

You must be logged in to vote

Call await ActivePageIndexChanged.InvokeAsync(ActivePageIndex); after every line of code that modifies the value of ActivePageIndex property.

That is almost what I'd recommend, except you shouldn't directly call the setter of an incoming [Parameter] property. See https://learn.microsoft.com/en-us/aspnet/core/blazor/components/overwriting-parameters?view=aspnetcore-7.0

Instead the way you modify your "ActivePageIndex" should be exclusively by calling ActivePageIndexChanged.InvokeAsync(newValue), then the parent component that uses @bind-ActivePageIndex will receive the new value, re-render itself, and in turn cause your child component to be re-rendered with the new ActivePageIndex.

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@Xyncgas
Comment options

@daniel-p-tech
Comment options

Comment options

You must be logged in to vote
1 reply
@daniel-p-tech
Comment options

Answer selected by daniel-p-tech
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
area-blazor Includes: Blazor, Razor Components
3 participants
Converted from issue

This discussion was converted from issue #49186 on July 03, 2023 16:57.