//******************************************************************************************************
// ErrorLogUserControl.xaml.cs - Gbtc
//
// Copyright © 2010, Grid Protection Alliance. All Rights Reserved.
//
// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
// the NOTICE file distributed with this work for additional information regarding copyright ownership.
// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may
// not use this file except in compliance with the License. You may obtain a copy of the License at:
//
// http://www.opensource.org/licenses/MIT
//
// Unless agreed to in writing, the subject software distributed under the License is distributed on an
// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
// License for the specific language governing permissions and limitations.
//
// Code Modification History:
// ----------------------------------------------------------------------------------------------------
// 03/27/2012 - prasanthgs
// Generated original version of source code.
// 04/12/2012 - prasanthgs
// Reworked as per the comments of codeplex reviewers.
// Code Optimized.
// 09/10/2012 - Aniket Salver
// Added paging technique and implemented sorting.
//
//******************************************************************************************************
using System;
using System.ComponentModel;
using System.Linq;
using System.Windows.Controls;
using GSF.TimeSeries.UI.ViewModels;
namespace GSF.TimeSeries.UI.UserControls
{
///
/// Interaction logic for ErrorLogUserControl.xaml
///
public partial class ErrorLogUserControl : UserControl
{
#region [ Members ]
private readonly ErrorLogViewModel m_dataContext;
private DataGridColumn m_sortColumn;
private string m_sortMemberPath;
private ListSortDirection m_sortDirection;
#endregion
#region [ Constructor ]
///
/// Constructor for Error user control class.
/// Creates data source with page size 18.
///
public ErrorLogUserControl()
{
InitializeComponent();
m_dataContext = new ErrorLogViewModel(18);
m_dataContext.PropertyChanged += ViewModel_PropertyChanged;
this.DataContext = m_dataContext;
m_sortColumn = DataGridList.Columns.Single(column => (string)column.Header == "Sl No.");
m_sortMemberPath = "ID";
m_sortDirection = ListSortDirection.Descending;
m_dataContext.SortData(m_sortMemberPath, m_sortDirection);
}
#endregion
#region [ Methods ]
private void DataGrid_Sorting(object sender, DataGridSortingEventArgs e)
{
if (e.Column.SortMemberPath != m_sortMemberPath)
m_sortDirection = ListSortDirection.Ascending;
else if (m_sortDirection == ListSortDirection.Ascending)
m_sortDirection = ListSortDirection.Descending;
else
m_sortDirection = ListSortDirection.Ascending;
m_sortColumn = e.Column;
m_sortMemberPath = e.Column.SortMemberPath;
m_dataContext.SortData(m_sortMemberPath, m_sortDirection);
}
private void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "ItemsSource")
Dispatcher.BeginInvoke(new Action(SortDataGrid));
}
private void SortDataGrid()
{
if ((object)m_sortColumn != null)
{
m_sortColumn.SortDirection = m_sortDirection;
DataGridList.Items.SortDescriptions.Clear();
DataGridList.Items.SortDescriptions.Add(new SortDescription(m_sortMemberPath, m_sortDirection));
DataGridList.Items.Refresh();
}
}
#endregion
}
}