Skip to content

Commit 4514d9f

Browse files
committed
Merge pull request #189 from ButchersBoy/FishNChips
Chip control dev branch - work in progress
2 parents 6390677 + 96e7c70 commit 4514d9f

12 files changed

+495
-5
lines changed

MainDemo.Wpf/Chips.xaml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<UserControl x:Class="MaterialDesignColors.WpfExample.Chips"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:MaterialDesignColors.WpfExample"
7+
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
8+
mc:Ignorable="d"
9+
d:DesignHeight="300" d:DesignWidth="300">
10+
<Grid Margin="32">
11+
<Grid.RowDefinitions>
12+
<RowDefinition Height="Auto" />
13+
<RowDefinition Height="Auto" />
14+
</Grid.RowDefinitions>
15+
<TextBlock Style="{StaticResource MaterialDesignTitleTextBlock}">Chips</TextBlock>
16+
<StackPanel Grid.Row="1" Margin="0 16 0 0">
17+
<WrapPanel Orientation="Horizontal">
18+
<materialDesign:Chip Content="James Willock" Margin="0 0 6 4">
19+
<materialDesign:Chip.Icon>
20+
<Image Source="Resources/ProfilePic.jpg" />
21+
</materialDesign:Chip.Icon>
22+
</materialDesign:Chip>
23+
<materialDesign:Chip Margin="0 0 4 4">
24+
Example Chip
25+
</materialDesign:Chip>
26+
<materialDesign:Chip Content="ANZ Bank"
27+
Icon="A"
28+
Margin="0 0 4 4" />
29+
<materialDesign:Chip Content="ZNA Inc"
30+
Icon="Z"
31+
Margin="0 0 4 4" />
32+
<materialDesign:Chip Content="Twitter"
33+
IconBackground="{DynamicResource PrimaryHueDarkBrush}"
34+
IconForeground="{DynamicResource PrimaryHueDarkForegroundBrush}"
35+
Margin="0 0 4 4">
36+
<materialDesign:Chip.Icon>
37+
<materialDesign:PackIcon Kind="Twitter"></materialDesign:PackIcon>
38+
</materialDesign:Chip.Icon>
39+
</materialDesign:Chip>
40+
</WrapPanel>
41+
<WrapPanel Margin="0 12 0 0" Orientation="Horizontal">
42+
<materialDesign:Chip Content="James Willock"
43+
IsDeletable="True"
44+
Margin="0 0 4 4"
45+
x:Name="ButtonsDemoChip"
46+
Click="ButtonsDemoChip_OnClick"
47+
DeleteClick="ButtonsDemoChip_OnDeleteClick"
48+
ToolTip="Just a tool tip"
49+
DeleteToolTip="Your friendly neighbour delete button"
50+
>
51+
<materialDesign:Chip.Icon>
52+
<Image Source="Resources/ProfilePic.jpg"></Image>
53+
</materialDesign:Chip.Icon>
54+
</materialDesign:Chip>
55+
<materialDesign:Chip Content="Example Chip"
56+
IsDeletable="True"
57+
ToolTip="This is an example chip"
58+
Margin="0 0 4 4">
59+
</materialDesign:Chip>
60+
<materialDesign:Chip Content="ANZ Bank"
61+
Icon="A"
62+
IsDeletable="True"
63+
Margin="0 0 4 4" />
64+
<materialDesign:Chip Content="ZNA Inc"
65+
Icon="Z"
66+
IsDeletable="True"
67+
IconBackground="{DynamicResource PrimaryHueLightBrush}"
68+
IconForeground="{DynamicResource PrimaryHueLightForegroundBrush}"
69+
Margin="0 0 4 4" />
70+
</WrapPanel>
71+
</StackPanel>
72+
</Grid>
73+
</UserControl>

MainDemo.Wpf/Chips.xaml.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Data;
9+
using System.Windows.Documents;
10+
using System.Windows.Input;
11+
using System.Windows.Media;
12+
using System.Windows.Media.Imaging;
13+
using System.Windows.Navigation;
14+
using System.Windows.Shapes;
15+
16+
namespace MaterialDesignColors.WpfExample
17+
{
18+
/// <summary>
19+
/// Interaction logic for Chips.xaml
20+
/// </summary>
21+
public partial class Chips : UserControl
22+
{
23+
public Chips()
24+
{
25+
InitializeComponent();
26+
}
27+
28+
private void ButtonsDemoChip_OnClick(object sender, RoutedEventArgs e)
29+
{
30+
Console.WriteLine("Chip clicked.");
31+
}
32+
33+
private void ButtonsDemoChip_OnDeleteClick(object sender, RoutedEventArgs e)
34+
{
35+
Console.WriteLine("Chip delete clicked.");
36+
}
37+
38+
}
39+
}

MainDemo.Wpf/MainWindow.xaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@
8888
<wpfExample:Sliders />
8989
</domain:DemoItem.Content>
9090
</domain:DemoItem>
91+
<domain:DemoItem Name="Chips">
92+
<domain:DemoItem.Content>
93+
<wpfExample:Chips />
94+
</domain:DemoItem.Content>
95+
</domain:DemoItem>
9196
<domain:DemoItem Name="Typography">
9297
<domain:DemoItem.Content>
9398
<wpfExample:Typography />

MainDemo.Wpf/MaterialDesignDemo.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
<Compile Include="Cards.xaml.cs">
7777
<DependentUpon>Cards.xaml</DependentUpon>
7878
</Compile>
79+
<Compile Include="Chips.xaml.cs">
80+
<DependentUpon>Chips.xaml</DependentUpon>
81+
</Compile>
7982
<Compile Include="ColorZones.xaml.cs">
8083
<DependentUpon>ColorZones.xaml</DependentUpon>
8184
</Compile>
@@ -192,6 +195,10 @@
192195
<SubType>Designer</SubType>
193196
<Generator>MSBuild:Compile</Generator>
194197
</Page>
198+
<Page Include="Chips.xaml">
199+
<SubType>Designer</SubType>
200+
<Generator>MSBuild:Compile</Generator>
201+
</Page>
195202
<Page Include="ColorZones.xaml">
196203
<SubType>Designer</SubType>
197204
<Generator>MSBuild:Compile</Generator>

MainDemo.Wpf/ProvingGround.xaml

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,61 @@
2222
</UserControl.Resources>
2323

2424

25-
<StackPanel Margin="24" HorizontalAlignment="Stretch">
26-
<ProgressBar Style="{StaticResource MaterialDesignCircularProgressBar}" Value="20" />
25+
<StackPanel>
26+
<WrapPanel Margin="24" Orientation="Horizontal">
27+
<materialDesign:Chip Content="James Willock" Margin="0 0 6 4">
28+
<materialDesign:Chip.Icon>
29+
<Image Source="Resources/ProfilePic.jpg" />
30+
</materialDesign:Chip.Icon>
31+
</materialDesign:Chip>
32+
<materialDesign:Chip Margin="0 0 4 4">
33+
Example Chip
34+
</materialDesign:Chip>
35+
<materialDesign:Chip Content="ANZ Bank"
36+
Icon="A"
37+
Margin="0 0 4 4" />
38+
<materialDesign:Chip Content="ZNA Inc"
39+
Icon="Z"
40+
Margin="0 0 4 4" />
41+
<materialDesign:Chip Content="Twitter"
42+
IconBackground="{DynamicResource PrimaryHueDarkBrush}"
43+
IconForeground="{DynamicResource PrimaryHueDarkForegroundBrush}"
44+
Margin="0 0 4 4">
45+
<materialDesign:Chip.Icon>
46+
<materialDesign:PackIcon Kind="Twitter"></materialDesign:PackIcon>
47+
</materialDesign:Chip.Icon>
48+
</materialDesign:Chip>
49+
</WrapPanel>
50+
<WrapPanel Margin="24" Orientation="Horizontal">
51+
<materialDesign:Chip Content="James Willock"
52+
IsDeletable="True"
53+
Margin="0 0 4 4"
54+
x:Name="ButtonsDemoChip"
55+
Click="ButtonsDemoChip_OnClick"
56+
DeleteClick="ButtonsDemoChip_OnDeleteClick"
57+
ToolTip="Just a tool tip"
58+
DeleteToolTip="Your friendly neighbour delete button"
59+
>
60+
<materialDesign:Chip.Icon>
61+
<Image Source="Resources/ProfilePic.jpg"></Image>
62+
</materialDesign:Chip.Icon>
63+
</materialDesign:Chip>
64+
<materialDesign:Chip Content="Example Chip"
65+
IsDeletable="True"
66+
ToolTip="This is an example chip"
67+
Margin="0 0 4 4">
68+
</materialDesign:Chip>
69+
<materialDesign:Chip Content="ANZ Bank"
70+
Icon="A"
71+
IsDeletable="True"
72+
Margin="0 0 4 4" />
73+
<materialDesign:Chip Content="ZNA Inc"
74+
Icon="Z"
75+
IsDeletable="True"
76+
IconBackground="{DynamicResource PrimaryHueLightBrush}"
77+
IconForeground="{DynamicResource PrimaryHueLightForegroundBrush}"
78+
Margin="0 0 4 4" />
79+
</WrapPanel>
2780
</StackPanel>
2881

2982
</UserControl>

MainDemo.Wpf/ProvingGround.xaml.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ private void Button_Click(object sender, RoutedEventArgs e)
3535
System.Diagnostics.Process.Start("https://twitter.com/James_Willock");
3636

3737
}
38+
39+
private void ButtonsDemoChip_OnClick(object sender, RoutedEventArgs e)
40+
{
41+
Console.WriteLine("Chip clicked.");
42+
}
43+
44+
private void ButtonsDemoChip_OnDeleteClick(object sender, RoutedEventArgs e)
45+
{
46+
Console.WriteLine("Chip delete clicked.");
47+
}
3848
}
3949

4050
public class ProvingGroundViewModel : INotifyPropertyChanged

MaterialDesignThemes.Wpf/Chip.cs

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
using System.Windows.Controls;
9+
using System.Windows.Controls.Primitives;
10+
using System.Windows.Input;
11+
using System.Windows.Media;
12+
13+
namespace MaterialDesignThemes.Wpf
14+
{
15+
[TemplatePart(Name = DeleteButtonPartName, Type = typeof(Button))]
16+
public class Chip : ButtonBase
17+
{
18+
private ButtonBase _deleteButton;
19+
20+
public const string DeleteButtonPartName = "PART_DeleteButton";
21+
22+
static Chip()
23+
{
24+
DefaultStyleKeyProperty.OverrideMetadata(typeof(Chip), new FrameworkPropertyMetadata(typeof(Chip)));
25+
}
26+
27+
public static readonly DependencyProperty IconProperty = DependencyProperty.Register(
28+
"Icon", typeof (object), typeof (Chip), new PropertyMetadata(default(object)));
29+
30+
public object Icon
31+
{
32+
get { return (object) GetValue(IconProperty); }
33+
set { SetValue(IconProperty, value); }
34+
}
35+
36+
public static readonly DependencyProperty IconBackgroundProperty = DependencyProperty.Register(
37+
"IconBackground", typeof (Brush), typeof (Chip), new PropertyMetadata(default(Brush)));
38+
39+
public Brush IconBackground
40+
{
41+
get { return (Brush) GetValue(IconBackgroundProperty); }
42+
set { SetValue(IconBackgroundProperty, value); }
43+
}
44+
45+
public static readonly DependencyProperty IconForegroundProperty = DependencyProperty.Register(
46+
"IconForeground", typeof (Brush), typeof (Chip), new PropertyMetadata(default(Brush)));
47+
48+
public Brush IconForeground
49+
{
50+
get { return (Brush) GetValue(IconForegroundProperty); }
51+
set { SetValue(IconForegroundProperty, value); }
52+
}
53+
54+
public static readonly DependencyProperty IsDeletableProperty = DependencyProperty.Register(
55+
"IsDeletable", typeof (bool), typeof (Chip), new PropertyMetadata(default(bool)));
56+
57+
/// <summary>
58+
/// Indicates if the delete button should be visible.
59+
/// </summary>
60+
public bool IsDeletable
61+
{
62+
get { return (bool) GetValue(IsDeletableProperty); }
63+
set { SetValue(IsDeletableProperty, value); }
64+
}
65+
66+
public static readonly DependencyProperty DeleteCommandProperty = DependencyProperty.Register(
67+
"DeleteCommand", typeof (ICommand), typeof (Chip), new PropertyMetadata(default(ICommand)));
68+
69+
public ICommand DeleteCommand
70+
{
71+
get { return (ICommand) GetValue(DeleteCommandProperty); }
72+
set { SetValue(DeleteCommandProperty, value); }
73+
}
74+
75+
public static readonly DependencyProperty DeleteCommandParameterProperty = DependencyProperty.Register(
76+
"DeleteCommandParameter", typeof (object), typeof (Chip), new PropertyMetadata(default(object)));
77+
78+
public object DeleteCommandParameter
79+
{
80+
get { return (object) GetValue(DeleteCommandParameterProperty); }
81+
set { SetValue(DeleteCommandParameterProperty, value); }
82+
}
83+
84+
public static readonly DependencyProperty DeleteToolTipProperty = DependencyProperty.Register(
85+
"DeleteToolTip", typeof (object), typeof (Chip), new PropertyMetadata(default(object)));
86+
87+
public object DeleteToolTip
88+
{
89+
get { return (object) GetValue(DeleteToolTipProperty); }
90+
set { SetValue(DeleteToolTipProperty, value); }
91+
}
92+
93+
/// <summary>
94+
/// Event correspond to delete button left mouse button click
95+
/// </summary>
96+
public static readonly RoutedEvent DeleteClickEvent = EventManager.RegisterRoutedEvent("DeleteClick", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(Chip));
97+
98+
/// <summary>
99+
/// Add / Remove DeleteClickEvent handler
100+
/// </summary>
101+
[Category("Behavior")]
102+
public event RoutedEventHandler DeleteClick { add { AddHandler(DeleteClickEvent, value); } remove { RemoveHandler(DeleteClickEvent, value); } }
103+
104+
public override void OnApplyTemplate()
105+
{
106+
if (_deleteButton != null)
107+
_deleteButton.Click -= DeleteButtonOnClick;
108+
109+
_deleteButton = GetTemplateChild(DeleteButtonPartName) as ButtonBase;
110+
if (_deleteButton != null)
111+
_deleteButton.Click += DeleteButtonOnClick;
112+
113+
base.OnApplyTemplate();
114+
}
115+
116+
protected virtual void OnDeleteClick()
117+
{
118+
var newEvent = new RoutedEventArgs(DeleteClickEvent, this);
119+
RaiseEvent(newEvent);
120+
121+
var command = DeleteCommand;
122+
if (command != null && command.CanExecute(DeleteCommandParameter))
123+
command.Execute(DeleteCommandParameter);
124+
}
125+
126+
private void DeleteButtonOnClick(object sender, RoutedEventArgs routedEventArgs)
127+
{
128+
OnDeleteClick();
129+
routedEventArgs.Handled = true;
130+
}
131+
}
132+
}

MaterialDesignThemes.Wpf/MaterialDesignThemes.Wpf.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
<SubType>Designer</SubType>
7676
<Generator>MSBuild:Compile</Generator>
7777
</Page>
78+
<Page Include="Themes\MaterialDesignTheme.Chip.xaml">
79+
<SubType>Designer</SubType>
80+
<Generator>MSBuild:Compile</Generator>
81+
</Page>
7882
<Page Include="Themes\MaterialDesignTheme.Clock.xaml">
7983
<SubType>Designer</SubType>
8084
<Generator>MSBuild:Compile</Generator>
@@ -218,6 +222,7 @@
218222
</ItemGroup>
219223
<ItemGroup>
220224
<Compile Include="Card.cs" />
225+
<Compile Include="Chip.cs" />
221226
<Compile Include="Clock.cs" />
222227
<Compile Include="ClockChoiceMadeEventArgs.cs" />
223228
<Compile Include="ClockItemButton.cs" />

0 commit comments

Comments
 (0)