Reputation: 151
I will do my best to explain my problem:
First I wanted a calendar that shows only the month, I make it
<Calendar x:Name="_Calendar" DisplayMode="Year" DisplayModeChanged="_Calendar_DisplayModeChanged" DisplayDateChanged="_Calendar_DisplayDateChanged"/>
Then when DisplayModeChanged is fire I simple do this:
private void _Calendar_DisplayModeChanged(Object InSender, CalendarModeChangedEventArgs InE)
{
if (_Calendar.DisplayMode != CalendarMode.Year)
{
_Calendar.DisplayMode = CalendarMode.Year;
}
}
Its all good until I want to refresh data on my grid when user change the selected month, for example:
private void _Calendar_DisplayDateChanged(Object InSender, CalendarDateChangedEventArgs InE)
{
_RefreshGrid();
}
The first time (I mean before user interact with the calendar), the grid is refresh ok, and if user hover the mouse over the others month nothing happens (I want this). But after the user click on another month the grid is refresh OK again, but when user just hover the others month the grid is refreshed again, I want the grid to refresh only when the user CLICK on other month.
So DisplayDateChanged is fired when user hover...
Its strange because if I put a messagebox in _RefreshGrid() then the hover doens't fire DisplayDateChanged.
Hope you can understand, if not I can try explain better.
Thanks!!
EDIT: I think the problem is with focus, the error dont happens with messagebox because messagebox get the focus, when I click on any date then if I hover over the others date the DisplayDateChanged is fired, but if I click in another place first dont have this problem.
Upvotes: 3
Views: 2434
Reputation: 151
This solved my problem:
private void _Calendar_PreviewMouseUp(object sender, MouseButtonEventArgs e)
{
if (Mouse.Captured is CalendarItem)
{
Mouse.Capture(null);
}
}
Upvotes: 6