Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 71 additions & 12 deletions MahApps.Metro/Controls/Helper/DataGridCellHelper.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
using System;
using System.Windows;
using System.Windows;
using System.Windows.Controls;

namespace MahApps.Metro.Controls
{
using System;
using System.ComponentModel;

public class DataGridCellHelper
{
public static readonly DependencyProperty SaveDataGridProperty =
DependencyProperty.RegisterAttached("SaveDataGrid", typeof(bool), typeof(DataGridCellHelper),
new FrameworkPropertyMetadata(default(bool),
FrameworkPropertyMetadataOptions.Inherits | FrameworkPropertyMetadataOptions.AffectsMeasure,
CellPropertyChangedCallback));
[Obsolete(@"This property will be deleted in the next release.")]
public static readonly DependencyProperty SaveDataGridProperty
= DependencyProperty.RegisterAttached("SaveDataGrid",
typeof(bool),
typeof(DataGridCellHelper),
new FrameworkPropertyMetadata(default(bool), CellPropertyChangedCallback));

private static void CellPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
Expand Down Expand Up @@ -50,7 +51,6 @@ static void DataGridCellUnloaded(object sender, RoutedEventArgs e)
/// <summary>
/// Save the DataGrid.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(DataGridCell))]
public static bool GetSaveDataGrid(UIElement element)
{
Expand All @@ -62,14 +62,16 @@ public static void SetSaveDataGrid(UIElement element, bool value)
element.SetValue(SaveDataGridProperty, value);
}

public static readonly DependencyProperty DataGridProperty =
DependencyProperty.RegisterAttached("DataGrid", typeof(DataGrid), typeof(DataGridCellHelper),
new FrameworkPropertyMetadata(default(DataGrid), FrameworkPropertyMetadataOptions.Inherits | FrameworkPropertyMetadataOptions.AffectsMeasure));
[Obsolete(@"This property will be deleted in the next release.")]
public static readonly DependencyProperty DataGridProperty
= DependencyProperty.RegisterAttached("DataGrid",
typeof(DataGrid),
typeof(DataGridCellHelper),
new FrameworkPropertyMetadata(default(DataGrid)));

/// <summary>
/// Get the DataGrid.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(DataGridCell))]
public static DataGrid GetDataGrid(UIElement element)
{
Expand All @@ -80,5 +82,62 @@ public static void SetDataGrid(UIElement element, DataGrid value)
{
element.SetValue(DataGridProperty, value);
}

public static readonly DependencyProperty SelectionUnitProperty
= DependencyProperty.RegisterAttached("SelectionUnit",
typeof(DataGridSelectionUnit),
typeof(DataGridCellHelper),
new FrameworkPropertyMetadata(DataGridSelectionUnit.Cell, SelectionUnitOnPropertyChangedCallback));

private static void SelectionUnitOnPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
{
if (args.OldValue != args.NewValue)
{
var cell = (DataGridCell)dependencyObject;
SetIsCellOrRowHeader(cell, !Equals(args.NewValue, DataGridSelectionUnit.FullRow));
}
}

/// <summary>
/// Gets the value to define the DataGridCell selection behavior.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(DataGridCell))]
public static DataGridSelectionUnit GetSelectionUnit(UIElement element)
{
return (DataGridSelectionUnit)element.GetValue(SelectionUnitProperty);
}

/// <summary>
/// Sets the value to define the DataGridCell selection behavior.
/// </summary>
public static void SetSelectionUnit(UIElement element, DataGridSelectionUnit value)
{
element.SetValue(SelectionUnitProperty, value);
}

public static readonly DependencyProperty IsCellOrRowHeaderProperty
= DependencyProperty.RegisterAttached("IsCellOrRowHeader",
typeof(bool),
typeof(DataGridCellHelper),
new FrameworkPropertyMetadata(true));

/// <summary>
/// Gets the value to define the DataGridCell selection behavior.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(DataGridCell))]
public static bool GetIsCellOrRowHeader(UIElement element)
{
return (bool)element.GetValue(IsCellOrRowHeaderProperty);
}

/// <summary>
/// Sets the value to define the DataGridCell selection behavior.
/// </summary>
internal static void SetIsCellOrRowHeader(UIElement element, bool value)
{
element.SetValue(IsCellOrRowHeaderProperty, value);
}
}
}
1 change: 0 additions & 1 deletion MahApps.Metro/Controls/Helper/DataGridRowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ public static void SetSelectionUnit(UIElement element, DataGridSelectionUnit val
{
element.SetValue(SelectionUnitProperty, value);
}

}
}
Loading