0

I'm trying to combine the NotifyIcon-WPF and ModernUI for WPF into a new, simple WPF app. This is a proof-of-concept type of app. At this point I'm not using MVVM; everything at this point is code-behind.

I'm trying to get a modern button to close a window that has a user control on it, the ModernButton is on the user control. First I implemented the Click event, but that didn't work. Next I tried the ModernButton's MouseDown event, but that too didn't work. So next I set a breakpoint in both events to see if they ever fired; the breakpoints were never hit. I don't understand why not.

Here's the XAML:

<mui:ModernButton EllipseDiameter="17" 
              IconWidth="15" 
              IconHeight="15" 
              x:Name="CloseButton"
              IconData="{StaticResource CancelIconData}" 
              HorizontalAlignment="Right"
              ToolTip="Close toast message"
              MouseDown="CloseButton_MouseDown"
              Click="CloseButton_Click" />

And here is the relevant C# code behind events:

private void CloseButton_Click(object sender, RoutedEventArgs e)
{
//the tray icon assigned this attached property to simplify access
TaskbarIcon taskbarIcon = TaskbarIcon.GetParentTaskbarIcon(this);
taskbarIcon.CloseBalloon();
}

private void CloseButton_MouseDown(object sender, MouseButtonEventArgs e)
{
//the tray icon assigned this attached property to simplify access
TaskbarIcon taskbarIcon = TaskbarIcon.GetParentTaskbarIcon(this);
taskbarIcon.CloseBalloon();
}
Rod
  • 4,107
  • 12
  • 57
  • 81
  • Tried just now and it worked for me. What's your `IconData`'s `CancelIconData`? – Szabolcs Dézsi Jan 11 '16 at 22:14
  • Its a PathGeometry object defined in the user control's resources. M19.85228,12.08996L12.093,19.849201 24.242323,31.997846 12.094,44.145998 19.852051,51.904958 32.001186,39.756277 44.150543,51.904958 51.909,44.145994 39.760246,31.997501 51.909,19.849201 44.15049,12.08996 32.001431,24.238849z M32,0C49.671021,3.1599484E-07 64,14.329407 64,31.998501 64,49.677606 49.671021,63.997003 32,63.997003 14.328003,63.997003 0,49.677606 0,31.998501 0,14.329407 14.328003,3.1599484E-07 32,0z – Rod Jan 11 '16 at 22:24
  • What if you try the `PreviewMouseLeftButtonUp="CloseButton_PreviewMouseLeftButtonUp"` event? – Szabolcs Dézsi Jan 11 '16 at 22:28
  • OK, just tried the PreviewMouseLeftButtonUp event. It did fire, if I clicked on it twice. (Not a double click but 2 separate clicks with a delay between the 2.) I guess that sort of works, but it's odd that I'd have to do that. I'm going to reboot my PC and see if that has an effect. – Rod Jan 11 '16 at 22:39
  • Rebooting it seems to have helped. The PreviewMouseLeftButtonUp event fires first, followed by the Click event. Oh well, in the immortal words of Roy Trenneman of The IT Crowd, "Have you turned it off and back on again." I'm sorry I bothered everyone. – Rod Jan 11 '16 at 22:58

0 Answers0