C
C#3mo ago
Häng

Disable Blazor NavLink

Is there any way to disable a NavLink in Blazor? While my application is doing some long calculations I want to prevent the user to navigate to another page.
5 Replies
Nefario
Nefario3mo ago
you can add loading bar and pop up?.
Häng
Häng3mo ago
Do you mean like adding an overlapping loading animation that prevents the user from clicking on anything else? I have a button that cancels the calculations though.
Nefario
Nefario3mo ago
well in that case add an overlapping loading animation and add Cancel button on that popup... :awesome: or add a.. State? like if State A then disable this if State B then enable it?. i often do this on Unity whenever i want to playaround with the unity prefab, but im not so sure if this OK in blazor. :TeBeCat:
Häng
Häng3mo ago
I'll try that Thank you =)))
Apache
Apache3mo ago
AdvancedNavLink.razor:
@(Disabled)
{
<div class="@DisabledClass">
@ChildContent
</div>
}
else
{
<NavLink href="@Href" class="@Class" ActiveClass="@ActiveClass" Match="@Match">
@ChildContent
</NavLink>
}

@code {
[Parameter]
public RenderFragment ChildContent { get; set; }

[Parameter]
public string Href { get; set; }

[Parameter]
public string Class { get; set; }

[Parameter]
public string ActiveClass { get; set; }

[Parameter]
public string DisabledClass { get; set; }

[Parameter]
public NavLinkMatch Match { get; set; }

[Parameter]
public bool Disabled { get; set; }
}
@(Disabled)
{
<div class="@DisabledClass">
@ChildContent
</div>
}
else
{
<NavLink href="@Href" class="@Class" ActiveClass="@ActiveClass" Match="@Match">
@ChildContent
</NavLink>
}

@code {
[Parameter]
public RenderFragment ChildContent { get; set; }

[Parameter]
public string Href { get; set; }

[Parameter]
public string Class { get; set; }

[Parameter]
public string ActiveClass { get; set; }

[Parameter]
public string DisabledClass { get; set; }

[Parameter]
public NavLinkMatch Match { get; set; }

[Parameter]
public bool Disabled { get; set; }
}
Usage:
<AdvancedNavLink Disabled="@_disableLinks"
Href="https://..."
Class="text-lg font-semibold"
ActiveClass="text-lg font-bold text-blue-700"
DisabledClass="text-lg font-medium text-grey-300">
Click Me!
</AdvancedNavLink>
<AdvancedNavLink Disabled="@_disableLinks"
Href="https://..."
Class="text-lg font-semibold"
ActiveClass="text-lg font-bold text-blue-700"
DisabledClass="text-lg font-medium text-grey-300">
Click Me!
</AdvancedNavLink>
Want results from more Discord servers?
Add your server
More Posts
Asp.net Login and SignupI have form where user can login or sign up but I need help with form saving the credentials to data✅ C# + raylib + freebsdHi All, I'm running FreeBSD 14 Release, dotnet 8.0 compiled from Ports and Raylib 5.0 downloaded f✅ Setting Foreign key as Primary Key (EF Core)I want to set a foreign key as my primary key in a link table im using. How would I do this in EF CoWinform my button to reset my picturebox and fill it in with a new generated image is not workinghttps://hatebin.com/cslhmvmnya - my code Lines 121-124 is the methos to reset the picturebox but ImVS Project config questions1. Is it bad to enable "Place solution and project in the same folder"? It sounds neater to me but w(Blazor) I'm having trouble accessing a variable inside a parent component.I'm trying to access a simple bool in a parent component that shows when my side bar has been collap✅ There is already an open DataReader associated with this Command which must be closed firstI'm currently developing a Point Of Sale software in winforms c#. While working on cash management mC# Integration with MulesoftWe are looking to re-do an application in microservice style and biz req is pushing Mulesoft for thaVisual Studio opening search results in the search dock, not main windowKinda unrelated to C#, but since a few updates ago Visual Studio started behaving weirdly for me. Logic on properly deploying thingsSo I've been getting into a more professional workflow (id say) with better github practices, workin