C# MVVM Tutorial Thanks to Powenetics!

Make It with a Hotkey

Let me start by explaining what a hotkey is: a key or a combination of keys on a computer keyboard that performs a task when pressed simultaneously.

I didn’t want to use a button but a key combination to achieve the background image change, so I had to modify the HotKeys class. I have already assigned CTRL + ALT + F1 for this task, so I only have to write the corresponding code:

public void Change_BigReadings_Background()
{
//MessageBox.Show(“TTTTTTT”); //For Testing Purposes!
_BigReadings.SelectBackgroundImage2();
}

What I do here: I call the SelectBackgroundImage2() method from an instance of BigReadings, and boom, the background image changes. The HotKeys constructor is the following:

public HotKeys(MainWindow frm)
{
this.m = frm;
_ScreenCapture = new ScreenCapture(m);
_BigReadings = new BigReadings(false);
}

Before the constructor, I have a reference to BigReadings, which goes like this: BigReadings _BigReadings;

I need to emphasize that without the “this.DataContext = _TestViewModel;” line in the BigReadings constructor, the HotKeys corresponding method won’t work because the UI won’t be notified of the change.

Pages ( 4 of 5 ): « Previous123 4 5Next »

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Please consider turning off your adblocker to support our work! We work night and day to offer quality content, and ads help us continue our work! Thank you! The Hardware Busters Team