FloatingActionButton.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System.Windows;
  2. using System.Windows.Controls;
  3. namespace CustomUI
  4. {
  5. public class FloatingActionButton : ContentControl
  6. {
  7. #region private fields
  8. #endregion
  9. #region Property
  10. private FloatingActionMenu ParentItemsControl
  11. {
  12. get { return this.ParentSelector as FloatingActionMenu; }
  13. }
  14. internal ItemsControl ParentSelector
  15. {
  16. get { return ItemsControl.ItemsControlFromItemContainer(this) as ItemsControl; }
  17. }
  18. #endregion
  19. #region DependencyProperty
  20. #region TipContent
  21. public string TipContent
  22. {
  23. get { return (string)GetValue(TipContentProperty); }
  24. set { SetValue(TipContentProperty, value); }
  25. }
  26. public static readonly DependencyProperty TipContentProperty =
  27. DependencyProperty.Register("TipContent", typeof(string), typeof(FloatingActionButton), new PropertyMetadata(string.Empty));
  28. #endregion
  29. #endregion
  30. #region Constructors
  31. static FloatingActionButton()
  32. {
  33. DefaultStyleKeyProperty.OverrideMetadata(typeof(FloatingActionButton), new FrameworkPropertyMetadata(typeof(FloatingActionButton)));
  34. }
  35. #endregion
  36. #region Override
  37. public override void OnApplyTemplate()
  38. {
  39. base.OnApplyTemplate();
  40. this.MouseLeftButtonDown += FloatingActionButton_MouseLeftButtonDown;
  41. }
  42. private void FloatingActionButton_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  43. {
  44. if(this.ParentItemsControl != null)
  45. {
  46. this.ParentItemsControl.OnItemClick(this.Content, this.Content);
  47. this.ParentItemsControl.IsDropDownOpen = false;
  48. }
  49. }
  50. #endregion
  51. #region private function
  52. #endregion
  53. #region Event Implement Function
  54. #endregion
  55. }
  56. }