MenuItemHelper.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Windows.Media.Imaging;
  5. namespace MuchInfo.Chart.WPF.Helpers
  6. {
  7. public class MenuItemHelper
  8. {
  9. /// <summary>
  10. /// Creates the menu item.
  11. /// </summary>
  12. /// <param name="title">The title.</param>
  13. /// <param name="image">The image.</param>
  14. /// <param name="onclick">The onclick.</param>
  15. /// <returns>MenuItem.</returns>
  16. public static MenuItem CreateMenuItem(string title, BitmapImage image, EventHandler onclick)
  17. {
  18. var item = new MenuItem()
  19. {
  20. Icon = new Image() { Source = image },
  21. Header = new TextBlock()
  22. {
  23. MinWidth = 60,
  24. Padding = new Thickness(8, 4, 12, 4),
  25. Text = title
  26. }
  27. };
  28. item.PreviewMouseLeftButtonDown += (s, e) =>
  29. {
  30. if (onclick != null)
  31. {
  32. onclick.Invoke(s, e);
  33. }
  34. e.Handled = true;
  35. };
  36. return item;
  37. }
  38. }
  39. }