title: Wpf Dependency Property Dynamic Key Down
body: <p>I don't know if my title is proper.</p>
  
  <p>But what i am doing here is I am creating a Program that draw rectangle on canvas. </p>
  
  <p>As of now i can draw on canvas by triggering a dependency property when i press the  <code>SHIFT</code> key on keyboard. But i want it to become dynamic. I create another Dependency Property then on my XAML i can pass the KEY </p>
  
  <p>something like this on my XAML</p>
  
  <pre><code>DrawingTrigger="Ctrl+Shift"
  </code></pre>
  
  <p>As of now this is my class</p>
  
  <pre><code>class WindowHelper : Behavior&lt;Window&gt;
      {
  
  
          public bool IsDrawing
          {
              get { return (bool)GetValue(IsDrawingProperty); }
              set { SetValue(IsDrawingProperty, value); }
          }
  
          // Using a DependencyProperty as the backing store for IsDrawing.  This enables animation, styling, binding, etc...
          public static readonly DependencyProperty IsDrawingProperty =
              DependencyProperty.Register("IsDrawing", typeof(bool), typeof(WindowHelper),
                  new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, null));
  
          protected override void OnAttached()
          {
              AssociatedObject.KeyDown += AssociatedObject_KeyDown;
              AssociatedObject.KeyUp += AssociatedObject_KeyUp;
  
              base.OnAttached();
          }
  
          private void AssociatedObject_KeyUp(object sender, KeyEventArgs e)
          {
              if (e.Key == Key.LeftShift || e.Key == Key.RightShift)
                  IsDrawing = false;
          }
  
          private void AssociatedObject_KeyDown(object sender, KeyEventArgs e)
          {
              if (e.Key == Key.LeftShift || e.Key == Key.RightShift)
                  IsDrawing = true;
  
  
          }
  
          protected override void OnDetaching()
          {
              AssociatedObject.KeyDown -= AssociatedObject_KeyDown;
              AssociatedObject.KeyUp -= AssociatedObject_KeyUp;
              base.OnDetaching();
          }
  
  
      }
  </code></pre>
  
  <p>And upon searching i found a code that print the Keyboard Modifiers pressed</p>
  
  <pre><code>            Console.WriteLine(Keyboard.Modifiers);
  </code></pre>
  
  <p>With the Keyboard Modifier. When i pressed the Ctrl+Shift+Alt</p>
  
  <p>it gives me</p>
  
  <pre><code>Alt, Control, Shift
  </code></pre>
  
  <p>With this how can i use this to solve my problem?</p>
  
  <p>Is it a good practice to check if each word in the <code>DrawingTrigger</code> is found the set the <code>IsDrawing</code> into <code>True</code> or any suggestion.</p>