Skip to content

Commit

Permalink
Merge pull request #57 from Astone/order-changed-event
Browse files Browse the repository at this point in the history
Add OrderChanged event to DataGrid
  • Loading branch information
RicoSuter committed Apr 6, 2016
2 parents 3241749 + 3f20d05 commit bb30b9a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/MyToolkit.Extended/Controls/DataGrid/DataGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public DataGrid()
/// <summary>Occurs when the selected item (row) has changed. </summary>
public event EventHandler<SelectionChangedEventArgs> SelectionChanged;

/// <summary>Occurs when the order (column) has changed. </summary>
public event EventHandler<DataGridColumnEventArgs> OrderChanged;

/// <summary>Occurs when the user clicked on an item and wants to navigate to its detail page. </summary>
public event EventHandler<NavigationListEventArgs> Navigate;

Expand Down Expand Up @@ -216,7 +219,7 @@ public bool SelectColumn(DataGridColumnBase column, bool ascending)
SelectedColumn.IsSelected = true;
SelectedColumn.IsAscending = ascending;

UpdateItemsOrder();
OnOrderChanged(this, new DataGridColumnEventArgs(SelectedColumn));
return true;
}
return false;
Expand Down Expand Up @@ -315,6 +318,15 @@ private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
copy(this, e);
}

private void OnOrderChanged(object sender, DataGridColumnEventArgs e)
{
UpdateItemsOrder();

var copy = OrderChanged;
if (copy != null)
copy(this, e);
}

private void ChangeItemSelection(object item, bool isSelected)
{
var listBoxItem = _listControl.GetListBoxItemFromItem(item);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//-----------------------------------------------------------------------
// <copyright file="DataGridColumnEventArgs.cs" company="MyToolkit">
// Copyright (c) Bram Stoeller. All rights reserved.
// </copyright>
// <license>https://github.com/MyToolkit/MyToolkit/blob/master/LICENSE.md</license>
// <author>Bram Stoeller, [email protected]</author>
//-----------------------------------------------------------------------

#if WINRT

using MyToolkit.Controls;
using System;

namespace MyToolkit.Controls
{
public class DataGridColumnEventArgs : EventArgs
{
internal DataGridColumnEventArgs(DataGridColumnBase column)
{
Column = column;
}

/// <summary>Gets ordering column. </summary>
public DataGridColumnBase Column { private set; get; }

}
}

#endif
1 change: 1 addition & 0 deletions src/MyToolkit.Extended/MyToolkit.Extended.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Controls\DataGrid\DataGridColumnBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\DataGrid\DataGridColumnCollection.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\DataGrid\DataGridExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\DataGrid\DataGridColumnEventArgs.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\DataGrid\DataGridRow.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\DataGrid\DataGridTemplatedCell.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\DataGrid\DataGridTemplatedColumn.cs" />
Expand Down
6 changes: 6 additions & 0 deletions src/SampleUwpApp/Views/DataGridPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<StackPanel>
Expand Down Expand Up @@ -56,6 +57,11 @@
</Style>
</controls:DataGrid.RowStyle>-->
</controls:DataGrid>

<StackPanel Grid.Row="2" HorizontalAlignment="Right" Margin="0,10,10,0">
<TextBlock Text="Loading" x:Name="Status" />
</StackPanel>

</Grid>
</Grid>
</paging:MtPage>
8 changes: 8 additions & 0 deletions src/SampleUwpApp/Views/DataGridPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ public DataGridPage()
p.Category.ToLower().Contains(Model.Filter.ToLower()));
}
};
DataGrid.OrderChanged += (sender, args) =>
{
Status.Text = string.Format(
"Items are ordered by {0} ({1})",
args.Column.OrderPropertyPath.Path,
(args.Column.IsAscending ? "ascending" : "descending")
);
};
}

public DataGridPageModel Model
Expand Down

0 comments on commit bb30b9a

Please sign in to comment.