P
P
postya2020-01-11 19:08:21
JavaScript
postya, 2020-01-11 19:08:21

How to transfer pressing hotkeys to a separate class?

Application in C# + WPF
In one window, I have a method that handles pressing hotkeys. In this case, I use the "Tilda" key.
I would not like to have methods for processing all keys for each window, but to make a general class that would process all hotkeys for all windows of the application
How to transfer the hotkey methods to a separate class?
QuestWindow.xaml:

<Window x:Class="ToolkitsNew.QuestWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:local="clr-namespace:ToolkitsNew"
        mc:Ignorable="d"
        Closing="CloseQuestionWindow"
        Icon="images/icons/icon without logo.ico"
        Background="#535353"
        Topmost="True"
        KeyDown="ShowPreviewCard"
        Title="Card Editor"
        WindowStartupLocation="CenterScreen"
        Height="500"
        Width="734">

QuestWindow.cs:
private void ShowPreviewCard(object sender, KeyEventArgs e)
        {
           
            if (e.Key == Key.OemTilde)
            {
                e.Handled = true;
                if (keyTilde == 0)
                {                   
                    window.Topmost = true;
                    window.cardText.Text = questionTextBox.Text;
                    window.cardBorder.Visibility = Visibility.Visible;
                    keyTilde = 1;
                }
                
                else if (keyTilde == 1)
                {
                    window.cardText.Text = answerTextBox.Text;                    
                    keyTilde = 2;
                }
                
                else if (keyTilde == 2)
                {                    
                    window.cardBorder.Visibility = Visibility.Hidden;                   
                    keyTilde = 0;
                    this.Visibility = Visibility.Visible;
                    window.Topmost = false;
                }
            }
             
        }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stockholm Syndrome, 2019-03-24
@Flexx97

what you have cartWrapperis a collection of NodeList elements that does not have the querySelector method you are trying to call on that line
empty = cartWrapper.querySelector('.empty');

R
Roman, 2020-01-11
@yarosroman

Make it into a separate class with a method and in the window constructor

this.KeyDown += new KeyEventHandler(YourClass.KeyHandler);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question