I have a button and a message that should be shown if condition is true.
<button @onclick="Helper.CallFunc">Call async func</button>
@if(Helper.Loading)
{
@("Loading...")
}
LoadingHelper
class look like this
public class LoadingHelper
{
public bool Loading { get; private set; } = false;
public Func<Task> PassedFunc { private get; set; } = async () => await Task.Delay(2000);
public Func<Task> CallFunc => async () =>
{
Loading = true;
await PassedFunc();
Loading = false;
};
}
When I define Helper
object like this the message is indeed shown for 2000 miliseconds
LoadingHelper Helper { get; set; } = new()
{
PassedFunc = async () => await Task.Delay(2000)
};
However when it's defined like this the message is never shown
LoadingHelper Helper => new()
{
PassedFunc = async () => await Task.Delay(2000)
};
I'm a little bit confused here as to why the Loading
change is not shown in second example. Shouldn't the change be visible regardless if the Helper
object is set with getter
and setter
or only getter
since I'm not modifying the Loading
property directly?
Edit When it's defined like this for some reason it works
LoadingHelper Helper { get; } = new()
{
PassedFunc = async () => await Task.Delay(2000)
};