Skip to content

Commit d4eb505

Browse files
committed
2 parents 65043f0 + 76d142c commit d4eb505

18 files changed

+517
-59
lines changed

MaterialDesignColors.WpfExample/Domain/ListFieldsViewModel.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ private static ObservableCollection<SelectableViewModel> CreateData()
5858
{
5959
Code = 'D',
6060
Name = "Dragablz",
61-
Description = "Dragablz Tab Control"
61+
Description = "Dragablz Tab Control",
62+
Food = "Fries"
6263
},
6364
new SelectableViewModel
6465
{
@@ -92,5 +93,16 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName
9293
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
9394
//PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
9495
}
96+
97+
public IEnumerable<string> Foods
98+
{
99+
get
100+
{
101+
yield return "Burger";
102+
yield return "Fries";
103+
yield return "Shake";
104+
yield return "Lettuce";
105+
}
106+
}
95107
}
96108
}

MaterialDesignColors.WpfExample/Domain/SelectableViewModel.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
namespace MaterialDesignColors.WpfExample.Domain
66
{
7+
78
public class SelectableViewModel : INotifyPropertyChanged
89
{
910
private bool _isSelected;
1011
private string _name;
1112
private string _description;
1213
private char _code;
13-
private double _numeric;
14+
private double _numeric;
15+
private string _food;
1416

1517
public bool IsSelected
1618
{
@@ -65,7 +67,18 @@ public double Numeric
6567
_numeric = value;
6668
OnPropertyChanged();
6769
}
68-
}
70+
}
71+
72+
public string Food
73+
{
74+
get { return _food; }
75+
set
76+
{
77+
if (_food == value) return;
78+
_food = value;
79+
OnPropertyChanged();
80+
}
81+
}
6982

7083
public event PropertyChangedEventHandler PropertyChanged;
7184

MaterialDesignColors.WpfExample/ListsWindow.xaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:domain="clr-namespace:MaterialDesignColors.WpfExample.Domain"
5-
xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters;assembly=MaterialDesignThemes.Wpf"
5+
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
6+
Background="{DynamicResource MaterialDesignPaper}"
7+
FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto"
68
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf"
79
Title="Lists &amp; Grids" Height="500" Width="800">
810
<Window.Resources>
@@ -131,6 +133,11 @@
131133
</Style>
132134
</DataGridTextColumn.ElementStyle>
133135
</wpf:MaterialDataGridTextColumn>
136+
137+
<!-- use custom combo box column to get better combos. Use ItemsSourceBinding as your binding template to be applied to each combo -->
138+
<wpf:MaterialDataGridComboBoxColumn Header="Food"
139+
SelectedValueBinding="{Binding Food}"
140+
ItemsSourceBinding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=DataContext.Foods}" />
134141
</DataGrid.Columns>
135142
</DataGrid>
136143
</TabItem>

MaterialDesignThemes.Wpf/DataGridAssist.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ public static void SetAutoGeneratedEditingTextStyle(DependencyObject element, St
7878
public static Style GetAutoGeneratedEditingTextStyle(DependencyObject element)
7979
{
8080
return (Style) element.GetValue(AutoGeneratedEditingTextStyleProperty);
81-
}
81+
}
8282
}
8383
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
using System.Windows;
2+
using System.Windows.Controls;
3+
using System.Windows.Data;
4+
5+
namespace MaterialDesignThemes.Wpf
6+
{
7+
public class MaterialDataGridComboBoxColumn : DataGridComboBoxColumn //DataGridBoundColumn
8+
{
9+
static MaterialDataGridComboBoxColumn()
10+
{
11+
ElementStyleProperty.OverrideMetadata(typeof(MaterialDataGridComboBoxColumn), new FrameworkPropertyMetadata(DefaultElementStyle));
12+
EditingElementStyleProperty.OverrideMetadata(typeof(MaterialDataGridComboBoxColumn), new FrameworkPropertyMetadata(DefaultEditingElementStyle));
13+
}
14+
15+
public Binding ItemsSourceBinding { get; set; }
16+
17+
protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem)
18+
{
19+
var comboBox = base.GenerateElement(cell, cell);
20+
21+
if (ItemsSourceBinding != null)
22+
comboBox.SetBinding(ItemsControl.ItemsSourceProperty, ItemsSourceBinding);
23+
ApplyStyle(false, false, comboBox);
24+
25+
return comboBox;
26+
}
27+
28+
protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem)
29+
{
30+
var comboBox = (ComboBox)base.GenerateElement(cell, cell);
31+
32+
if (ItemsSourceBinding != null)
33+
comboBox.SetBinding(ItemsControl.ItemsSourceProperty, ItemsSourceBinding);
34+
ApplyStyle(true, false, comboBox);
35+
36+
return comboBox;
37+
}
38+
39+
public static new Style DefaultElementStyle
40+
{
41+
get
42+
{
43+
var comboBox = new ComboBox();
44+
45+
var brushKey = new ComponentResourceKey(typeof(ComboBox), "MaterialDataGridComboBoxColumnStyle");
46+
var style = (Style)comboBox.TryFindResource(brushKey);
47+
48+
return style;
49+
}
50+
}
51+
52+
public static new Style DefaultEditingElementStyle
53+
{
54+
get
55+
{
56+
var comboBox = new ComboBox();
57+
58+
var brushKey = new ComponentResourceKey(typeof(ComboBox), "MaterialDataGridComboBoxColumnEditingStyle");
59+
var style = (Style)comboBox.TryFindResource(brushKey);
60+
61+
return style;
62+
}
63+
}
64+
65+
private void ApplyStyle(bool isEditing, bool defaultToElementStyle, FrameworkElement element)
66+
{
67+
var style = PickStyle(isEditing, defaultToElementStyle);
68+
if (style != null)
69+
{
70+
element.Style = style;
71+
}
72+
}
73+
74+
private Style PickStyle(bool isEditing, bool defaultToElementStyle)
75+
{
76+
var style = isEditing ? EditingElementStyle : ElementStyle;
77+
if (isEditing && defaultToElementStyle && (style == null))
78+
{
79+
style = ElementStyle;
80+
}
81+
82+
return style;
83+
}
84+
85+
/*
86+
/// <summary>
87+
/// Assigns the Binding to the desired property on the target object.
88+
/// </summary>
89+
private void ApplyBinding(DependencyObject target, DependencyProperty property)
90+
{
91+
var binding = Binding;
92+
if (binding != null)
93+
{
94+
BindingOperations.SetBinding(target, property, binding);
95+
}
96+
else
97+
{
98+
BindingOperations.ClearBinding(target, property);
99+
}
100+
}
101+
*/
102+
103+
}
104+
}

MaterialDesignThemes.Wpf/MaterialDesignThemes.Wpf.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@
8080
<SubType>Designer</SubType>
8181
<Generator>MSBuild:Compile</Generator>
8282
</Page>
83+
<Page Include="Themes\MaterialDesignTheme.DataGrid.ComboBox.xaml">
84+
<SubType>Designer</SubType>
85+
<Generator>MSBuild:Compile</Generator>
86+
</Page>
8387
<Page Include="Themes\MaterialDesignTheme.DataGrid.xaml">
8488
<SubType>Designer</SubType>
8589
<Generator>MSBuild:Compile</Generator>
@@ -169,6 +173,7 @@
169173
<Compile Include="DataGridAssist.cs" />
170174
<Compile Include="DateTimeEx.cs" />
171175
<Compile Include="ListSortDirectionIndicator.cs" />
176+
<Compile Include="MaterialDataGridComboBoxColumn.cs" />
172177
<Compile Include="MaterialDataGridTextColumn.cs" />
173178
<Compile Include="MaterialDateDisplay.cs" />
174179
<Compile Include="PaletteHelper.cs" />

MaterialDesignThemes.Wpf/Themes/Generic.xaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@
2121
<!-- set up default styles for our custom Material Design in XAML Toolkit controls -->
2222
<Style TargetType="{x:Type local:Clock}" BasedOn="{StaticResource MaterialDesignClock}" />
2323
<Style TargetType="{x:Type local:TimePicker}" BasedOn="{StaticResource MaterialDesignTimePicker}" />
24-
25-
<!-- TODO freeze, share, theme -->
26-
<SolidColorBrush x:Key="AttentionToActionBrush" Color="Black" Opacity="1" />
27-
24+
2825
<converters:BrushToRadialGradientBrushConverter x:Key="BrushToRadialGradientBrushConverter" />
2926

3027
<Style TargetType="{x:Type local:VisualFeedbackContentControl}">

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Button.xaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3-
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf">
3+
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf"
4+
xmlns:po="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options">
5+
6+
<ResourceDictionary.MergedDictionaries>
7+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Shadows.xaml" />
8+
</ResourceDictionary.MergedDictionaries>
49

510
<Style x:Key="FocusVisual">
611
<Setter Property="Control.Template">
@@ -11,9 +16,8 @@
1116
</Setter.Value>
1217
</Setter>
1318
</Style>
14-
15-
<!-- TODO freeze, share, theme -->
16-
<SolidColorBrush x:Key="AttentionToActionBrush" Color="Black" Opacity=".23" />
19+
20+
<SolidColorBrush x:Key="AttentionToActionBrush" Color="{StaticResource MaterialDesignShadow}" Opacity=".23" po:Freeze="True" />
1721

1822
<Style x:Key="MaterialDesignRaisedButton" TargetType="{x:Type Button}">
1923
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
@@ -30,7 +34,7 @@
3034
<Setter.Value>
3135
<ControlTemplate TargetType="{x:Type Button}">
3236
<Grid>
33-
<Border Background="{TemplateBinding Background}" Effect="{DynamicResource MaterialDesignShadowDepth1}" />
37+
<Border Background="{TemplateBinding Background}" Effect="{StaticResource MaterialDesignShadowDepth1}" />
3438
<Border Background="{TemplateBinding Background}" x:Name="border" CornerRadius="2">
3539
<wpf:VisualFeedbackContentControl Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" Focusable="False"
3640
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Card.xaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf"
44
xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters">
55

6+
<ResourceDictionary.MergedDictionaries>
7+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Shadows.xaml" />
8+
</ResourceDictionary.MergedDictionaries>
9+
610
<converters:CardClipConverter x:Key="CardClipConverter" />
711

812
<ControlTemplate TargetType="{x:Type wpf:Card}" x:Key="CardTemplate">
913
<Border Margin="{TemplateBinding Margin}"
10-
Effect="{DynamicResource MaterialDesignShadowDepth2}"
14+
Effect="{StaticResource MaterialDesignShadowDepth2}"
1115
CornerRadius="{TemplateBinding UniformCornerRadius}" Background="Transparent">
1216
<Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"
1317
x:Name="PART_ClipBorder"

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ComboBox.xaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf"
44
xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters">
55

6+
<ResourceDictionary.MergedDictionaries>
7+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Shadows.xaml" />
8+
</ResourceDictionary.MergedDictionaries>
9+
610
<converters:TextFieldHintVisibilityConverter x:Key="TextFieldHintVisibilityConverter" />
711

812
<Style x:Key="FocusVisual">
@@ -154,7 +158,7 @@
154158
<Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
155159
<Border x:Name="shadow" Background="{DynamicResource MaterialDesignPaper}" CornerRadius="2"
156160
MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=templateRoot}"
157-
BorderThickness="1" BorderBrush="{DynamicResource MaterialDesignDivider}" Effect="{DynamicResource MaterialDesignShadowDepth2}">
161+
BorderThickness="1" BorderBrush="{DynamicResource MaterialDesignDivider}" Effect="{StaticResource MaterialDesignShadowDepth2}">
158162
<Border x:Name="dropDownBorder" Background="Transparent">
159163
<ScrollViewer x:Name="DropDownScrollViewer">
160164
<Grid x:Name="grid" RenderOptions.ClearTypeHint="Enabled">
@@ -237,7 +241,7 @@
237241
<Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
238242
<Border x:Name="dropDownBorder" BorderBrush="{DynamicResource MaterialDesignDivider}" BorderThickness="1" Background="{DynamicResource MaterialDesignPaper}"
239243
CornerRadius="2"
240-
MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=templateRoot}" Effect="{DynamicResource MaterialDesignShadowDepth2}">
244+
MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=templateRoot}" Effect="{StaticResource MaterialDesignShadowDepth2}">
241245
<ScrollViewer x:Name="DropDownScrollViewer">
242246
<Grid x:Name="grid" RenderOptions.ClearTypeHint="Enabled">
243247
<Canvas x:Name="canvas" HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">

0 commit comments

Comments
 (0)