diff --git a/MainDemo.Wpf/Chips.xaml b/MainDemo.Wpf/Chips.xaml new file mode 100644 index 0000000000..8e12919457 --- /dev/null +++ b/MainDemo.Wpf/Chips.xaml @@ -0,0 +1,73 @@ + + + + + + + Chips + + + + + + + + + Example Chip + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MainDemo.Wpf/Chips.xaml.cs b/MainDemo.Wpf/Chips.xaml.cs new file mode 100644 index 0000000000..197eea420d --- /dev/null +++ b/MainDemo.Wpf/Chips.xaml.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace MaterialDesignColors.WpfExample +{ + /// + /// Interaction logic for Chips.xaml + /// + public partial class Chips : UserControl + { + public Chips() + { + InitializeComponent(); + } + + private void ButtonsDemoChip_OnClick(object sender, RoutedEventArgs e) + { + Console.WriteLine("Chip clicked."); + } + + private void ButtonsDemoChip_OnDeleteClick(object sender, RoutedEventArgs e) + { + Console.WriteLine("Chip delete clicked."); + } + + } +} diff --git a/MainDemo.Wpf/MainWindow.xaml b/MainDemo.Wpf/MainWindow.xaml index effc3ddb17..f020337cae 100644 --- a/MainDemo.Wpf/MainWindow.xaml +++ b/MainDemo.Wpf/MainWindow.xaml @@ -88,6 +88,11 @@ + + + + + diff --git a/MainDemo.Wpf/MaterialDesignDemo.csproj b/MainDemo.Wpf/MaterialDesignDemo.csproj index d8e2855b43..dffe42de11 100644 --- a/MainDemo.Wpf/MaterialDesignDemo.csproj +++ b/MainDemo.Wpf/MaterialDesignDemo.csproj @@ -76,6 +76,9 @@ Cards.xaml + + Chips.xaml + ColorZones.xaml @@ -192,6 +195,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/MainDemo.Wpf/ProvingGround.xaml b/MainDemo.Wpf/ProvingGround.xaml index d2d045b296..023b438a12 100644 --- a/MainDemo.Wpf/ProvingGround.xaml +++ b/MainDemo.Wpf/ProvingGround.xaml @@ -22,8 +22,61 @@ - - + + + + + + + + + Example Chip + + + + + + + + + + + + + + + + + + + + diff --git a/MainDemo.Wpf/ProvingGround.xaml.cs b/MainDemo.Wpf/ProvingGround.xaml.cs index 2a087b3ce1..093bb36428 100644 --- a/MainDemo.Wpf/ProvingGround.xaml.cs +++ b/MainDemo.Wpf/ProvingGround.xaml.cs @@ -35,6 +35,16 @@ private void Button_Click(object sender, RoutedEventArgs e) System.Diagnostics.Process.Start("https://twitter.com/James_Willock"); } + + private void ButtonsDemoChip_OnClick(object sender, RoutedEventArgs e) + { + Console.WriteLine("Chip clicked."); + } + + private void ButtonsDemoChip_OnDeleteClick(object sender, RoutedEventArgs e) + { + Console.WriteLine("Chip delete clicked."); + } } public class ProvingGroundViewModel : INotifyPropertyChanged diff --git a/MaterialDesignThemes.Wpf/Chip.cs b/MaterialDesignThemes.Wpf/Chip.cs new file mode 100644 index 0000000000..d3650da648 --- /dev/null +++ b/MaterialDesignThemes.Wpf/Chip.cs @@ -0,0 +1,132 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; +using System.Windows.Input; +using System.Windows.Media; + +namespace MaterialDesignThemes.Wpf +{ + [TemplatePart(Name = DeleteButtonPartName, Type = typeof(Button))] + public class Chip : ButtonBase + { + private ButtonBase _deleteButton; + + public const string DeleteButtonPartName = "PART_DeleteButton"; + + static Chip() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(Chip), new FrameworkPropertyMetadata(typeof(Chip))); + } + + public static readonly DependencyProperty IconProperty = DependencyProperty.Register( + "Icon", typeof (object), typeof (Chip), new PropertyMetadata(default(object))); + + public object Icon + { + get { return (object) GetValue(IconProperty); } + set { SetValue(IconProperty, value); } + } + + public static readonly DependencyProperty IconBackgroundProperty = DependencyProperty.Register( + "IconBackground", typeof (Brush), typeof (Chip), new PropertyMetadata(default(Brush))); + + public Brush IconBackground + { + get { return (Brush) GetValue(IconBackgroundProperty); } + set { SetValue(IconBackgroundProperty, value); } + } + + public static readonly DependencyProperty IconForegroundProperty = DependencyProperty.Register( + "IconForeground", typeof (Brush), typeof (Chip), new PropertyMetadata(default(Brush))); + + public Brush IconForeground + { + get { return (Brush) GetValue(IconForegroundProperty); } + set { SetValue(IconForegroundProperty, value); } + } + + public static readonly DependencyProperty IsDeletableProperty = DependencyProperty.Register( + "IsDeletable", typeof (bool), typeof (Chip), new PropertyMetadata(default(bool))); + + /// + /// Indicates if the delete button should be visible. + /// + public bool IsDeletable + { + get { return (bool) GetValue(IsDeletableProperty); } + set { SetValue(IsDeletableProperty, value); } + } + + public static readonly DependencyProperty DeleteCommandProperty = DependencyProperty.Register( + "DeleteCommand", typeof (ICommand), typeof (Chip), new PropertyMetadata(default(ICommand))); + + public ICommand DeleteCommand + { + get { return (ICommand) GetValue(DeleteCommandProperty); } + set { SetValue(DeleteCommandProperty, value); } + } + + public static readonly DependencyProperty DeleteCommandParameterProperty = DependencyProperty.Register( + "DeleteCommandParameter", typeof (object), typeof (Chip), new PropertyMetadata(default(object))); + + public object DeleteCommandParameter + { + get { return (object) GetValue(DeleteCommandParameterProperty); } + set { SetValue(DeleteCommandParameterProperty, value); } + } + + public static readonly DependencyProperty DeleteToolTipProperty = DependencyProperty.Register( + "DeleteToolTip", typeof (object), typeof (Chip), new PropertyMetadata(default(object))); + + public object DeleteToolTip + { + get { return (object) GetValue(DeleteToolTipProperty); } + set { SetValue(DeleteToolTipProperty, value); } + } + + /// + /// Event correspond to delete button left mouse button click + /// + public static readonly RoutedEvent DeleteClickEvent = EventManager.RegisterRoutedEvent("DeleteClick", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(Chip)); + + /// + /// Add / Remove DeleteClickEvent handler + /// + [Category("Behavior")] + public event RoutedEventHandler DeleteClick { add { AddHandler(DeleteClickEvent, value); } remove { RemoveHandler(DeleteClickEvent, value); } } + + public override void OnApplyTemplate() + { + if (_deleteButton != null) + _deleteButton.Click -= DeleteButtonOnClick; + + _deleteButton = GetTemplateChild(DeleteButtonPartName) as ButtonBase; + if (_deleteButton != null) + _deleteButton.Click += DeleteButtonOnClick; + + base.OnApplyTemplate(); + } + + protected virtual void OnDeleteClick() + { + var newEvent = new RoutedEventArgs(DeleteClickEvent, this); + RaiseEvent(newEvent); + + var command = DeleteCommand; + if (command != null && command.CanExecute(DeleteCommandParameter)) + command.Execute(DeleteCommandParameter); + } + + private void DeleteButtonOnClick(object sender, RoutedEventArgs routedEventArgs) + { + OnDeleteClick(); + routedEventArgs.Handled = true; + } + } +} diff --git a/MaterialDesignThemes.Wpf/MaterialDesignThemes.Wpf.csproj b/MaterialDesignThemes.Wpf/MaterialDesignThemes.Wpf.csproj index eb3c1404e0..709fd941ab 100644 --- a/MaterialDesignThemes.Wpf/MaterialDesignThemes.Wpf.csproj +++ b/MaterialDesignThemes.Wpf/MaterialDesignThemes.Wpf.csproj @@ -75,6 +75,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -218,6 +222,7 @@ + diff --git a/MaterialDesignThemes.Wpf/Themes/Generic.xaml b/MaterialDesignThemes.Wpf/Themes/Generic.xaml index 88f94989dd..671a76b1cb 100644 --- a/MaterialDesignThemes.Wpf/Themes/Generic.xaml +++ b/MaterialDesignThemes.Wpf/Themes/Generic.xaml @@ -16,6 +16,7 @@ in your App.xaml --> + @@ -32,7 +33,7 @@ - + - + + --> + + + \ No newline at end of file diff --git a/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Dark.xaml b/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Dark.xaml index 12d5d50f5a..204dcbee9f 100644 --- a/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Dark.xaml +++ b/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Dark.xaml @@ -26,4 +26,6 @@ + + \ No newline at end of file diff --git a/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Light.xaml b/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Light.xaml index ad8ce333fd..d4c388ce47 100644 --- a/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Light.xaml +++ b/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Light.xaml @@ -23,5 +23,7 @@ - + + + \ No newline at end of file