Skip to content

Commit a317703

Browse files
authored
Add SelectedCellBorderBrush attached property (#2800)
* add SelectedCellBorderBrush attached property * add demo datagrid * remove Inherits
1 parent 1f4a020 commit a317703

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

MainDemo.Wpf/DataGrids.xaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,17 @@
172172
materialDesign:DataGridAssist.ColumnHeaderPadding="4 2 2 2" />
173173

174174
</smtx:XamlDisplay>
175+
176+
<TextBlock
177+
Style="{StaticResource MaterialDesignHeadline6TextBlock}"
178+
Text="Custom Selected Cell Border Brush" Margin="0 24 0 0"/>
179+
180+
<smtx:XamlDisplay UniqueKey="grids_4">
181+
<DataGrid
182+
ItemsSource="{Binding Items1}"
183+
CanUserAddRows="False"
184+
materialDesign:DataGridAssist.SelectedCellBorderBrush="Crimson" />
185+
</smtx:XamlDisplay>
175186
</StackPanel>
176187
</UserControl>
177188

MaterialDesignThemes.Wpf/DataGridAssist.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Windows.Controls;
55
using System.Windows.Controls.Primitives;
66
using System.Windows.Input;
7+
using System.Windows.Media;
78

89
namespace MaterialDesignThemes.Wpf
910
{
@@ -136,6 +137,17 @@ public static void SetCellPadding(DataGrid element, Thickness value)
136137
=> element.SetValue(CellPaddingProperty, value);
137138
#endregion
138139

140+
#region AttachedProperty : SelectedCellBorderBrushProperty
141+
public static readonly DependencyProperty SelectedCellBorderBrushProperty
142+
= DependencyProperty.RegisterAttached("SelectedCellBorderBrush", typeof(Brush), typeof(DataGridAssist),
143+
new PropertyMetadata(null));
144+
145+
public static Brush GetSelectedCellBorderBrush(DataGrid element)
146+
=> (Brush)element.GetValue(SelectedCellBorderBrushProperty);
147+
public static void SetSelectedCellBorderBrush(DataGrid element, Brush value)
148+
=> element.SetValue(SelectedCellBorderBrushProperty, value);
149+
#endregion
150+
139151
#region AttachedProperty : ColumnHeaderPaddingProperty
140152
public static readonly DependencyProperty ColumnHeaderPaddingProperty
141153
= DependencyProperty.RegisterAttached("ColumnHeaderPadding", typeof(Thickness), typeof(DataGridAssist),

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DataGrid.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@
295295
</Setter>
296296
<Style.Triggers>
297297
<Trigger Property="IsKeyboardFocusWithin" Value="True">
298-
<Setter Property="BorderBrush" Value="{DynamicResource MaterialDesignTextBoxBorder}" />
298+
<Setter Property="BorderBrush" Value="{Binding RelativeSource={RelativeSource AncestorType=DataGrid}, Path=(wpf:DataGridAssist.SelectedCellBorderBrush)}" />
299299
</Trigger>
300300
<MultiDataTrigger>
301301
<MultiDataTrigger.Conditions>
@@ -527,6 +527,7 @@
527527
<Setter Property="wpf:DataGridAssist.AutoGeneratedTextStyle" Value="{StaticResource MaterialDesignDataGridTextColumnStyle}" />
528528
<Setter Property="wpf:DataGridAssist.AutoGeneratedEditingTextStyle" Value="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" />
529529
<Setter Property="wpf:DataGridAssist.EnableEditBoxAssist" Value="True" />
530+
<Setter Property="wpf:DataGridAssist.SelectedCellBorderBrush" Value="{DynamicResource MaterialDesignTextBoxBorder}"/>
530531
<Setter Property="Template">
531532
<Setter.Value>
532533
<ControlTemplate TargetType="{x:Type DataGrid}">

0 commit comments

Comments
 (0)