I have a ToggleSwitch defined in my XAML.
<ToggleSwitch x:Name="enable_toggle_button" Header="Turn on/off" OffContent="Disabled" OnContent="Enabled" IsOn="False" Toggled="ToggleSwitch_Toggled"/>
When my application loads up, i want to perform a check on my application. if my application is doing something, I want to auto set the toggle switch to on. If my app isnt doing something, I want it to set the toggle to off. Simples…
Inside the .cs constructor of my window, i have the following:
public home_page()
{
this.InitializeComponent();
Task.Run(() => { set_enabled_disabled_switch(); });
}
Set_enabled_disabled_switch() then looks like this:
private async Task set_enabled_disabled_switch()
{
bool is_it_running = await Ipc_handler.send_is_my_app_running_message() ; // Under the covers, this send an IPC pipe message to a back end component, that then returns to tell my GUI app if its running or not. it returns a true or false boolean.
if (is_it_running)
{
Trace.WriteLine("GUI:app is on, so enabling toggle switch", "info");
enable_toggle_button.IsOn = true;
}
else
{
Trace.WriteLine("GUI: App is off, so disabling toggle switch", "info");
enable_toggle_button.IsOn = false;
}
}
In my debug output, my trace.Writelines are printing the right thing. But the enable_toggle_button.IsOn = true or false doesnt seem to be working. the Toggle switch in the GUI isnt changing accordingly.
Any ideas what im doing wrong?
PS… is it me, or is the WinUi3 documentation really really confusing?