Eple
Eple
CC#
Created by Eple on 6/3/2024 in #help
✅ Help needed: Buttons update enabled state after two clicks.
Hello, I need help to find out why it takes two clicks before the buttons change the enabled state. Please see the attached video and also my code below:
<StackLayout>
<Button Text="Start the service" Command="{Binding StartTheServiceCommand}" />
</StackLayout>

<StackLayout>
<Button Text="Stop the service" Command="{Binding StopTheServiceCommand}" />
</StackLayout>
<StackLayout>
<Button Text="Start the service" Command="{Binding StartTheServiceCommand}" />
</StackLayout>

<StackLayout>
<Button Text="Stop the service" Command="{Binding StopTheServiceCommand}" />
</StackLayout>
public MainPageViewModel(ILogger<MainPageViewModel> logger, WorkerService workerService)
{
_logger = logger;
_workerService = workerService;

StartTheServiceCommand = new Command(
execute: () =>
{
_logger.LogInformation("Starting the service at: {time}", DateTimeOffset.Now);
Task.Run(async () => await _workerService.StartAsync(new()));
RefreshCanExecutes();
},
canExecute: () => !_workerService.IsRunning);

StopTheServiceCommand = new Command(
execute: () =>
{
_logger.LogInformation("Stopping the service at: {time}", DateTimeOffset.Now);
Task.Run(async () => await _workerService.StopAsync(new()));
RefreshCanExecutes();
},
canExecute: () => _workerService.IsRunning);
}

public ICommand StartTheServiceCommand { get; }
public ICommand StopTheServiceCommand { get; }

private void RefreshCanExecutes()
{
(StartTheServiceCommand as Command)!.ChangeCanExecute();
(StopTheServiceCommand as Command)!.ChangeCanExecute();
}
public MainPageViewModel(ILogger<MainPageViewModel> logger, WorkerService workerService)
{
_logger = logger;
_workerService = workerService;

StartTheServiceCommand = new Command(
execute: () =>
{
_logger.LogInformation("Starting the service at: {time}", DateTimeOffset.Now);
Task.Run(async () => await _workerService.StartAsync(new()));
RefreshCanExecutes();
},
canExecute: () => !_workerService.IsRunning);

StopTheServiceCommand = new Command(
execute: () =>
{
_logger.LogInformation("Stopping the service at: {time}", DateTimeOffset.Now);
Task.Run(async () => await _workerService.StopAsync(new()));
RefreshCanExecutes();
},
canExecute: () => _workerService.IsRunning);
}

public ICommand StartTheServiceCommand { get; }
public ICommand StopTheServiceCommand { get; }

private void RefreshCanExecutes()
{
(StartTheServiceCommand as Command)!.ChangeCanExecute();
(StopTheServiceCommand as Command)!.ChangeCanExecute();
}
8 replies
CC#
Created by Eple on 5/31/2024 in #help
Why does it give the error?
No description
3 replies
CC#
Created by Eple on 4/12/2024 in #help
Help Needed: Choosing Between VSCode on Mac or Visual Studio via Remote Desktop for Windows Backgrou
I'm starting a new project and can't decide between two options: using VSCode on my Mac or using Visual Studio on a Windows computer through remote desktop (the connection is fast and stable). The project is a background service that will eventually run on Windows. Any suggestions on which setup would be better for this?
10 replies
CC#
Created by Eple on 3/15/2024 in #help
Background Service and Blazor
Hi all, I wish to create a Service and a Blazor interface. Can someone help me get started? That is a Service doing some work and a Blazor interface communicating with it. I need help to choose the right project types.
14 replies
CC#
Created by Eple on 3/2/2023 in #help
❔ JObject find value
I have the following JSON
{
"sale": {
"id": "x",
"transaction": {
"id": "y",
"state": "Completed"
}
}
}
{
"sale": {
"id": "x",
"transaction": {
"id": "y",
"state": "Completed"
}
}
}
I want to check if sale.transaction.state == "Completed" But since the keys sale, transaction and state are optional and not always in the response, I must check for their presence. Is there a better way than what I have below?
var responseObject = JObject.Parse(responseString);
if (responseObject["sale"] != null && responseObject["sale"]["transaction"] != null && responseObject["sale"]["transaction"]["state"] != null)
{
if (responseObject.Value<string>("sale.transaction.state") == "Completed")
{
Console.WriteLine("Yes");
}
}
var responseObject = JObject.Parse(responseString);
if (responseObject["sale"] != null && responseObject["sale"]["transaction"] != null && responseObject["sale"]["transaction"]["state"] != null)
{
if (responseObject.Value<string>("sale.transaction.state") == "Completed")
{
Console.WriteLine("Yes");
}
}
7 replies
CC#
Created by Eple on 12/19/2022 in #help
❔ Where to store .exe file?
My ASP.NET application executes wkhtmltopdf.exe (convert html to pdf) - where is the best place to store wkhtmltopdf.exe?
2 replies
CC#
Created by Eple on 12/16/2022 in #help
❔ Update-Database error
2 replies
CC#
Created by Eple on 12/16/2022 in #help
❔ PDF generation library?
I'm looking for a way to generate PDF file in an ASP.NET application.
11 replies
CC#
Created by Eple on 12/7/2022 in #help
❔ problem with ModelState
2 replies
CC#
Created by Eple on 11/25/2022 in #help
❔ DbUpdateConcurrencyException
7 replies
CC#
Created by Eple on 11/22/2022 in #help
❔ How to make property auto-increment?
4 replies
CC#
Created by Eple on 11/6/2022 in #help
Edit Users
1 replies
CC#
Created by Eple on 11/5/2022 in #help
Web Application with separate protected areas
11 replies