There is a Calendar on the form, when I select a date in it, I have to click on any other element or empty space so that the other elements become active.

That is, after selecting a date, the calendar remains active. How to get rid of it? To not have to do an extra click?

There is nothing special about markup:

<Border Grid.Column="1"> <Calendar SelectedDate="{Binding SelectedDate}"/> </Border> 

It turns out that when I click on it and select a date, the cursor moves, but the rest of the elements are inactive (there is not even animation when you hover over the buttons). I have to make an "empty" click, and then the rest of the elements begin to respond.

  • Elements that change the activity after the click is tied to the teams? - Gardes
  • @Gardes yes, for example, when choosing a date, I move the cursor over the button and there is no animation, and I need to do 1 click, and then everything works ... - UporotayaPanda
  • show implementation of a command that inherits from ICommand - Gardes
  • @Gardes updated the question - UporotayaPanda
  • @Gardes threw textbox on the form, you still have to make an extra click - UporotayaPanda

1 answer 1

The fact is that Calendar designed to be placed in various pop-up elements (for example, such as the DatePicker ), so it captures (Capture) the mouse. The same behavior can be observed, for example, with the ComboBox , if you open the drop-down list, the first mouse click will close it and only the next one will be processed by the target element.

Fortunately, this behavior can be changed with the following code:

 if (Mouse.Captured is CalendarItem) Mouse.Capture(null); 

Paste it, for example, in your calendar's PreviewMouseUp handler.

  • does not help, subscribe to and to MouseUp and MouseDown. The result is the same ... - UporotayaPanda
  • I do not believe, create an empty project, add a button to the Calendar window and check. - Andrei NOP
  • Created a project on .Net 4.0, added MahApps, but did not change app.xaml, added code, you still need to double-click ... - UporotayaPanda
  • excuse me!!! my cant! many thanks !!! helped! - UporotayaPanda
  • Well, it's good that you figure it out :) - Andrey NOP