Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazor MudTabs setting the active tab programmatically

$
0
0

I'm trying to set the active tab programmatically but I cant get it to work, this is the tabs definition

<MudTabs Elevation="1" Rounded="true" @ref="tabs">

and this is the C# code I'm using to set the active tab

public required MudTabs tabs;-- defined at the top of code behindawait InvokeAsync(() => tabs.ActivatePanel(5,true));await InvokeAsync(StateHasChanged);

the active tab isn't being set here, If I use a non async version like this

tabs.ActivatePanel(5,true)await InvokeAsync(StateHasChanged);

I get this error

System.InvalidOperationException HResult=0x80131509 Message=Thecurrent thread is not associated with the Dispatcher. UseInvokeAsync() to switch execution to the Dispatcher when triggeringrendering or component state. Source=Microsoft.AspNetCore.ComponentsStackTrace: atMicrosoft.AspNetCore.Components.ComponentBase.StateHasChanged() in/_/src/Components/Components/src/ComponentBase.cs:line 117 atMudBlazor.MudTabs.d__174.MoveNext() atSystem.Threading.Tasks.Task.<>c.b__128_1(Object state)
at System.Threading.QueueUserWorkItemCallback.Execute() atSystem.Threading.ThreadPoolWorkQueue.Dispatch() atSystem.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()

can anyone see what I'm doing wrong here ?

(I'm aware its zero based, the tab number is the correct one I want to show)


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>