Mercurial > silverbladetech
view Messaging/Common/Controls/MetroTile.cs @ 35:83c1f62d9370
All working except image so far
author | adminsh@apollo |
---|---|
date | Tue, 27 Mar 2012 16:15:45 +0100 |
parents | |
children | c8c79f05d76f |
line wrap: on
line source
using System; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; namespace Common.Controls { [TemplatePart(Name="PART_DISPLAY_ICON", Type=typeof(Image))] [TemplatePart(Name = "PART_DISPLAY_COUNT_CONTAINER", Type = typeof(TextBlock))] [TemplatePart(Name = "PART_DISPLAY_TITLE_CONTAINER", Type = typeof(TextBlock))] public class MetroTile : UserControl { #region Constructor static MetroTile() { DefaultStyleKeyProperty.OverrideMetadata(typeof(MetroTile), new FrameworkPropertyMetadata(typeof(MetroTile))); CommandManager.RegisterClassCommandBinding( typeof(MetroTile), new CommandBinding(ResetCountCommand, OnResetCountCommand)); } #endregion #region Dependency Properties #region DisplayIcon /// <summary> /// Icon for the tile /// </summary> public static readonly DependencyProperty DisplayIconProperty = DependencyProperty.Register("DisplayIcon", typeof(Image), typeof(MetroTile), new PropertyMetadata(null)); public Image DisplayIcon { get { return (Image) this.GetValue(DisplayIconProperty); } set { this.SetValue(DisplayIconProperty, value); } } #endregion #region DisplayCount /// <summary> /// Display count for the tile /// </summary> public static readonly DependencyProperty DisplayCountProperty = DependencyProperty.Register("DisplayCount", typeof(int), typeof(MetroTile), new UIPropertyMetadata(0)); public int DisplayCount { get { return (int)this.GetValue(DisplayCountProperty); } set { this.SetValue(DisplayCountProperty, value); } } #endregion #region DisplayText /// <summary> /// Main Display text for the tile /// </summary> public static readonly DependencyProperty DisplayTextProperty = DependencyProperty.Register("DisplayText", typeof(string), typeof(MetroTile), new PropertyMetadata("Not set")); public string DisplayText { get { return (string)this.GetValue(DisplayTextProperty); } set { this.SetValue(DisplayTextProperty, value); } } #endregion #endregion #region Events public static readonly RoutedEvent DisplayCountChangedEvent = EventManager.RegisterRoutedEvent("DisplayCountChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MetroTile)); public event RoutedEventHandler DisplayCountChanged { add { AddHandler(DisplayCountChangedEvent, value); } remove { RemoveHandler(DisplayCountChangedEvent, value); } } protected virtual void OnDisplayCountChanged(int oldValue, int newValue) { // 1. Pair of events: A preview that tunnels and a main event that bubbles // 2. We could also create our own RoutedEventArgs that includes oldValue & new Value var previewEvent = new RoutedEventArgs(PreviewDisplayCountChangedEvent); RaiseEvent(previewEvent); var e = new RoutedEventArgs(DisplayCountChangedEvent); RaiseEvent(e); } public static readonly RoutedEvent PreviewDisplayCountChangedEvent = EventManager.RegisterRoutedEvent("PreviewDisplayCountChanged", RoutingStrategy.Tunnel, typeof(RoutedEventHandler), typeof(MetroTile)); public event RoutedEventHandler PreviewDisplayCountChanged { add { AddHandler(PreviewDisplayCountChangedEvent, value); } remove { RemoveHandler(PreviewDisplayCountChangedEvent, value); } } #endregion #region Commands public static readonly ICommand ResetCountCommand = new RoutedUICommand("ResetCount", "ResetCount", typeof(MetroTile)); private static void OnResetCountCommand(object sender, ExecutedRoutedEventArgs e) { var target = (MetroTile)sender; target.DisplayCount = 0; } #endregion } }