jeudi 5 mai 2022

Powershell WPF checkbox binding

First off, i'm aware of dozens of questions previously posted on this exact topic, i spent the last day reading around about it and did try a lot of different ways with no success.

I have a MenuItem Checkbox in my main window as well as in another two windows:

    <MenuItem x:Name = 'FileMenu' Header = '_File'>
        <MenuItem x:Name = 'EnableAutostart' Header = '_Enable Autostart' IsChecked="{Binding AutoStart, Mode= TwoWay}" IsCheckable="true" ToolTip = 'Enables the autostart.' InputGestureText ='Ctrl+S'></MenuItem>

I use it to define wheter or not the script automatically starts on user logon (a function checks for the scheduled activity and sets the checkbox accordingly) and when clicked it enables or disables it.

Now what if i want to keep all the 3 different windows checkboxes synched? I read a lot about binding but can't really get it working, i tryed to set the binding on a bool "Autostart" and to set it true before showing the window but it does nothing at all.

What's an easy way to define a bool in my code and make so whenever i change that bool it reflects on all the menuitems checkboxes bound to it? (even if the other windows are yet to be created/shown)

I read about i need to make it a property, can i just make a class, set a property to it called something like "AutoStart" and it would work?




Aucun commentaire:

Enregistrer un commentaire