Go Back
Virtuoso standard control libraries Power Button

Power Button

The Power Button control connects to the target model controller to power a virtual target on and off.


The PowerButton control functions as a toggle button to control the power state of one or more virtual targets at runtime. Thus, the virtual target may be powered on and off multiple times without restarting the host application.

The virtual target’s running state is controlled by an IBoolProperty object injected into the target’s IsRunning property setter, using a property dependency injection Inversion Of Control design pattern. The target model also uses its IsRunning property getter, which returns an IBoolProperty property interface which can be used to indicate that the target has been loaded into memory, the host has attached itself to the target, and the target is ready to run. Although the target model has a getter and setter for the IsRunning IBoolProperty property interface, the property getter returns a different object than the property setter. The property interface returned by the getter will show its value turned to true after the property interface injected into the setter has turned true, and the target initialization has completed.

Similarly, the PowerButton has a property getter and setter for a PowerOn IBoolProperty property. The getter returns an IBoolProperty which updates when the power button state is toggled. The setter is used to inject an IBoolProperty which indicates to the PowerButton that the system has finished responding to a power state change. The PowerButton will disable itself after the user toggles its value, until it sees that the system has finished responding to the change. This is to ensure that the user doesn’t press the power button multiple times before the target related components being turned on have finished initializing themselves.

The image below shows the basic wiring configuration for a target. The target model’s IsRunning property is set to the PowerButton view model’s PowerOn property getter, at which point the target model internally registers to the PowerOn IBoolProperty’s ValueChanged change notification. The PowerButton’s PowerOn property (setter) is then set to the target model’s IsRunning property (getter), at which point the PowerButton view model internally registers to the IsRunning IBoolProperty’s ValueChanged change notification. The result is that when the power button is pressed, the PowerOn state is set to true, and the Power button is disabled. The target is notified that it should run, at which point the host loads the target into memory, attaches itself to the target, and runs the target. This causes the IsRunning property getter’s value to change to true. This signals to the PowerButton that the system is initialized, and the PowerButton is then re-enabled so that the user is free to press it again to turn the target’s power off.

When a host has more than one target, separate power buttons may be used to independently control the power for each target independently. More commonly, however, when multiple targets are being virtualized, they are powered from the same power rail. In this case, a single power button may be used to power both targets. An AND gate can be used to AND the values of the two targets’ IsRunning properties, so that the PowerButton sees the system initialized when both targets have been loaded into memory and are running, as shown below.

Other components in the host may require a power input to function correctly. By chaining Boolean property interfaces as a sequence, power-up sequences can be carefully controlled to ensure that race conditions aren’t created. As an example, a TouchLCDDisplay has both IsPowered and IsRunning properties. The image below shows the power sequence designed such that the TouchLCDDisplay finishes its power initialization before the target is powered, then finally the PowerButton is notified when the target has finished running. A reset button is connected to the target through an AND gate, so that the target will reset when the reset button is pressed. The configuration of the power-up or reset process is completely up to the developer’s discretion based on the needs of the host application.

Add a PushButton control to the host view by opening MainWindow.xaml in the Solution Explorer, and dragging and dropping the Pushbutton control from the Virtuoso Standard Control Library Toolbox.

To the right of the PushButton control, click the topmost icon to open the PushButton Design Wizard.

Click “Submit” to submit the PowerButton configuration once all items have been specified. The PowerButton may be resized as needed by clicking on the PowerButton in the XAML design time viewer and using the resize handles. When deleting a PowerButton from a view after it has been configured by the wizard, you should use the “Delete” icon below the “Wizard” icon. If a PowerButton hasn’t been configured yet, you will need to just click on the PowerButton and press the delete button to remove it from the view.

When a PowerButton is dragged from the Virtuoso Standard Control Library to a window, this results in the XAML declaration as shown below to be added to the view.

The PowerButton component wizard automates the configuration of the PowerButton view component as a normal MVVM view component, just like a TextBox or a Button. Using the wizard to configure the PowerButton as outlined above performs the following standard MVVM design tasks in the background:

1) A PowerButtonViewModel component is added as a property of the specified Target ViewModel class, as shown below:

private PowerButtonViewModel _PowerButton;
public PowerButtonViewModel PowerButton
        return _PowerButton;

2) The PowerButtonViewModel component is constructed in the TargetViewModel initialization function based on the desired configuration. This is added as construction code in the Target ViewModel’s InitializeComponents method, as shown below.

_PowerButton = new PowerButtonViewModel(this, "VirtualDeviceIsPowered", LEDTileImage.Tile1, PowerButtonColor.Blue);

3) The DataContext property for or the PowerButton is bound to the new PowerButtonViewModel property exposed by the Target ViewModel, as shown below.