Skip to content

Commit 54664e5

Browse files
authored
Change binding type to support BindingBase (#2436)
Minor code cleanup Fixes #323
1 parent 31689b2 commit 54664e5

File tree

3 files changed

+46
-47
lines changed

3 files changed

+46
-47
lines changed

MaterialDesignThemes.Wpf/DataGridComboBoxColumn.cs

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

55
namespace MaterialDesignThemes.Wpf
66
{
7-
public class DataGridComboBoxColumn : System.Windows.Controls.DataGridComboBoxColumn //DataGridBoundColumn
7+
public class DataGridComboBoxColumn : System.Windows.Controls.DataGridComboBoxColumn
88
{
99
static DataGridComboBoxColumn()
1010
{
1111
ElementStyleProperty.OverrideMetadata(typeof(DataGridComboBoxColumn), new FrameworkPropertyMetadata(DefaultElementStyle));
1212
EditingElementStyleProperty.OverrideMetadata(typeof(DataGridComboBoxColumn), new FrameworkPropertyMetadata(DefaultEditingElementStyle));
1313
}
1414

15-
public Binding? ItemsSourceBinding { get; set; }
15+
public BindingBase? ItemsSourceBinding { get; set; }
1616

1717
public bool? IsEditable { get; set; }
1818

@@ -35,8 +35,8 @@ protected override FrameworkElement GenerateEditingElement(DataGridCell cell, ob
3535
comboBox.IsEditable = isEditable;
3636
}
3737

38-
if (ItemsSourceBinding != null)
39-
comboBox.SetBinding(ItemsControl.ItemsSourceProperty, ItemsSourceBinding);
38+
if (ItemsSourceBinding is { } binding)
39+
comboBox.SetBinding(ItemsControl.ItemsSourceProperty, binding);
4040
ApplyStyle(true, false, comboBox);
4141

4242
return comboBox;
@@ -70,14 +70,14 @@ protected override FrameworkElement GenerateEditingElement(DataGridCell cell, ob
7070

7171
private void ApplyStyle(bool isEditing, bool defaultToElementStyle, FrameworkElement element)
7272
{
73-
var style = PickStyle(isEditing, defaultToElementStyle);
73+
Style? style = PickStyle(isEditing, defaultToElementStyle);
7474
if (style != null)
7575
{
7676
element.Style = style;
7777
}
7878
}
7979

80-
private Style PickStyle(bool isEditing, bool defaultToElementStyle)
80+
private Style? PickStyle(bool isEditing, bool defaultToElementStyle)
8181
{
8282
var style = isEditing ? EditingElementStyle : ElementStyle;
8383
if (isEditing && defaultToElementStyle && (style == null))
@@ -88,14 +88,14 @@ private Style PickStyle(bool isEditing, bool defaultToElementStyle)
8888
return style;
8989
}
9090

91-
protected override void CancelCellEdit(FrameworkElement editingElement, object uneditedValue)
91+
protected override void CancelCellEdit(FrameworkElement? editingElement, object? uneditedValue)
9292
{
9393
if (editingElement is ComboBox comboBox)
9494
comboBox.SetCurrentValue(ComboBox.IsDropDownOpenProperty, false);
9595
base.CancelCellEdit(editingElement, uneditedValue);
9696
}
9797

98-
protected override bool CommitCellEdit(FrameworkElement editingElement)
98+
protected override bool CommitCellEdit(FrameworkElement? editingElement)
9999
{
100100
if (editingElement is ComboBox comboBox)
101101
comboBox.SetCurrentValue(ComboBox.IsDropDownOpenProperty, false);

MaterialDesignThemes.Wpf/DataGridTextColumn.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ public class DataGridTextColumn : System.Windows.Controls.DataGridTextColumn
77
{
88
protected override object? PrepareCellForEdit(FrameworkElement? editingElement, RoutedEventArgs editingEventArgs)
99
{
10-
var textBox = editingElement as TextBox;
11-
if (textBox != null)
10+
if (editingElement is TextBox textBox)
1211
{
1312
textBox.MaxLength = MaxLength;
1413
textBox.SelectionStart = textBox.Text.Length;

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Menu.xaml

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@
8585
<ScrollViewer x:Name="SubMenuScrollViewer" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
8686
<Grid RenderOptions.ClearTypeHint="Enabled" Margin="0 16">
8787
<ItemsPresenter x:Name="ItemsPresenter"
88-
KeyboardNavigation.DirectionalNavigation="Cycle"
89-
Grid.IsSharedSizeScope="True"
90-
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
91-
KeyboardNavigation.TabNavigation="Cycle"/>
88+
KeyboardNavigation.DirectionalNavigation="Cycle"
89+
Grid.IsSharedSizeScope="True"
90+
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
91+
KeyboardNavigation.TabNavigation="Cycle"/>
9292
</Grid>
9393
</ScrollViewer>
9494
</Border>
@@ -106,7 +106,7 @@
106106
<Setter.Value>
107107
<ControlTemplate TargetType="{x:Type MenuItem}">
108108
<ControlTemplate.Resources>
109-
<Style TargetType="{x:Type wpf:PackIcon}" >
109+
<Style TargetType="wpf:PackIcon">
110110
<Setter Property="FrameworkElement.Width" Value="16" />
111111
<Setter Property="FrameworkElement.Height" Value="16" />
112112
</Style>
@@ -124,36 +124,36 @@
124124
SnapsToDevicePixels="True"
125125
Opacity="0"/>
126126
<wpf:Ripple Background="Transparent"
127-
HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
128-
Focusable="False"
129-
Feedback="{TemplateBinding Foreground, Converter={StaticResource BrushRoundConverter}}">
127+
HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
128+
Focusable="False"
129+
Feedback="{TemplateBinding Foreground, Converter={StaticResource BrushRoundConverter}}">
130130
<Grid Height="{TemplateBinding Height}" Background="Transparent">
131131
<Grid VerticalAlignment="Center"
132-
Background="Transparent"
133-
Margin="{TemplateBinding Padding}">
132+
Background="Transparent"
133+
Margin="{TemplateBinding Padding}">
134134
<Grid.ColumnDefinitions>
135135
<ColumnDefinition Width="Auto" SharedSizeGroup="IconGroup"/>
136136
<ColumnDefinition Width="*" SharedSizeGroup="HeaderGroup"/>
137137
<ColumnDefinition Width="*"/>
138138
</Grid.ColumnDefinitions>
139139
<Grid x:Name="IconWrapper" Visibility="Visible" Width="40">
140140
<ContentPresenter x:Name="Icon"
141-
Content="{TemplateBinding Icon}"
142-
ContentSource="Icon"
143-
HorizontalAlignment="Left" VerticalAlignment="Center"
144-
Height="16" Width="16"
145-
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
141+
Content="{TemplateBinding Icon}"
142+
ContentSource="Icon"
143+
HorizontalAlignment="Left" VerticalAlignment="Center"
144+
Height="16" Width="16"
145+
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
146146
</Grid>
147147
<Grid x:Name="GlyphWrapper" Visibility="Collapsed" Width="40">
148148
<Viewbox x:Name="GlyphPanel"
149-
Width="16" Height="16"
150-
HorizontalAlignment="Left"
151-
Margin="0" Visibility="Collapsed" VerticalAlignment="Center"
152-
FlowDirection="LeftToRight">
149+
Width="16" Height="16"
150+
HorizontalAlignment="Left"
151+
Margin="0" Visibility="Collapsed" VerticalAlignment="Center"
152+
FlowDirection="LeftToRight">
153153
<Canvas Width="24" Height="24">
154154
<Path Data="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"
155-
x:Name="Glyph"
156-
Fill="{TemplateBinding Foreground}" FlowDirection="LeftToRight" />
155+
x:Name="Glyph"
156+
Fill="{TemplateBinding Foreground}" FlowDirection="LeftToRight" />
157157
</Canvas>
158158
</Viewbox>
159159
</Grid>
@@ -178,26 +178,26 @@
178178
VerticalAlignment="Center"/>
179179
</Grid>
180180
<Grid x:Name="InputGestureTextWrapper"
181-
Grid.Column="2"
182-
Visibility="Collapsed">
181+
Grid.Column="2"
182+
Visibility="Collapsed">
183183
<TextBlock Visibility="{TemplateBinding InputGestureText, Converter={StaticResource StringIsEmptyVisibilityConverter}}"
184-
Margin="16 0 0 0"
185-
VerticalAlignment="Center" HorizontalAlignment="Right"
186-
Text="{TemplateBinding InputGestureText}"
187-
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
188-
Foreground="{TemplateBinding Foreground}"/>
184+
Margin="16 0 0 0"
185+
VerticalAlignment="Center" HorizontalAlignment="Right"
186+
Text="{TemplateBinding InputGestureText}"
187+
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
188+
Foreground="{TemplateBinding Foreground}"/>
189189
</Grid>
190190
<Grid x:Name="SubBlock"
191-
Grid.Column="2"
192-
Visibility="Collapsed"
193-
Margin="16 0 0 0">
191+
Grid.Column="2"
192+
Visibility="Collapsed"
193+
Margin="16 0 0 0">
194194
<Path Width="5" Height="10"
195-
Stretch="Uniform"
196-
HorizontalAlignment="Right"
197-
VerticalAlignment="Center"
198-
Data="M0,16 L8,8 L0,0 Z"
199-
Fill="{TemplateBinding Foreground}"
200-
SnapsToDevicePixels="False"/>
195+
Stretch="Uniform"
196+
HorizontalAlignment="Right"
197+
VerticalAlignment="Center"
198+
Data="M0,16 L8,8 L0,0 Z"
199+
Fill="{TemplateBinding Foreground}"
200+
SnapsToDevicePixels="False"/>
201201
</Grid>
202202
</Grid>
203203
</Grid>

0 commit comments

Comments
 (0)