//******************************************************************************************************
// DataPagerUserControl.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:
// ----------------------------------------------------------------------------------------------------
// 04/12/2011 - mthakkar
// Generated original version of source code.
//
//******************************************************************************************************
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
namespace GSF.TimeSeries.UI.UserControls
{
///
/// Interaction logic for DataPagerUserControl.xaml
///
public partial class DataPagerUserControl : UserControl
{
#region [ Properties ]
//Dependency Properties
///
/// to display number of pages.
///
public static readonly DependencyProperty PageCountProperty = DependencyProperty.Register("PageCount", typeof(int), typeof(DataPagerUserControl), new UIPropertyMetadata(0));
///
/// for current page number.
///
public static readonly DependencyProperty CurrentPageNumberProperty = DependencyProperty.Register("CurrentPageNumber", typeof(int), typeof(DataPagerUserControl), new UIPropertyMetadata(0));
///
/// to bind to .
///
public static readonly DependencyProperty FirstCommandProperty = DependencyProperty.Register("FirstCommand", typeof(ICommand), typeof(DataPagerUserControl), new PropertyMetadata(null));
///
/// to bind to .
///
public static readonly DependencyProperty PreviousCommandProperty = DependencyProperty.Register("PreviousCommand", typeof(ICommand), typeof(DataPagerUserControl), new PropertyMetadata(null));
///
/// to bind to .
///
public static readonly DependencyProperty NextCommandProperty = DependencyProperty.Register("NextCommand", typeof(ICommand), typeof(DataPagerUserControl), new PropertyMetadata(null));
///
/// to bind to .
///
public static readonly DependencyProperty LastCommandProperty = DependencyProperty.Register("LastCommand", typeof(ICommand), typeof(DataPagerUserControl), new PropertyMetadata(null));
///
/// to bind to .
///
public static DependencyProperty ShowPageSizeProperty = DependencyProperty.Register("ShowPageSize", typeof(bool), typeof(DataPagerUserControl), new PropertyMetadata(true));
///
/// Gets or sets an index of the current page displayed in UI.
///
public int CurrentPageNumber
{
get
{
return (int)GetValue(CurrentPageNumberProperty);
}
set
{
SetValue(CurrentPageNumberProperty, value);
}
}
///
/// Gets or sets total number of pages.
///
public int PageCount
{
get
{
return (int)GetValue(PageCountProperty);
}
set
{
SetValue(PageCountProperty, value);
}
}
///
/// Gets or sets for moving to the first page.
///
public ICommand FirstCommand
{
get
{
return (ICommand)GetValue(FirstCommandProperty);
}
set
{
SetValue(FirstCommandProperty, value);
}
}
///
/// Gets or sets for moving to the previous page.
///
public ICommand PreviousCommand
{
get
{
return (ICommand)GetValue(PreviousCommandProperty);
}
set
{
SetValue(PreviousCommandProperty, value);
}
}
///
/// Gets or sets for moving to the next page.
///
public ICommand NextCommand
{
get
{
return (ICommand)GetValue(NextCommandProperty);
}
set
{
SetValue(NextCommandProperty, value);
}
}
///
/// Gets or sets for moving to the last page.
///
public ICommand LastCommand
{
get
{
return (ICommand)GetValue(LastCommandProperty);
}
set
{
SetValue(LastCommandProperty, value);
}
}
///
/// Gets or sets the boolean flag which determines whether
/// the page size should be shown on the control.
///
public bool ShowPageSize
{
get
{
return (bool)this.GetValue(ShowPageSizeProperty);
}
set
{
this.SetValue(ShowPageSizeProperty, value);
}
}
#endregion
#region [ Constructor ]
///
/// Creates a new instance of .
///
public DataPagerUserControl()
{
InitializeComponent();
}
#endregion
#region [ Methods ]
///
/// Invoked whenever the effective value of any dependency property on this
/// has been updated. The specific dependency property that changed is reported in the arguments parameter.
/// Overrides .
///
/// The event data that describes the property that changed, as well as old and new values.
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
if (e.Property == ShowPageSizeProperty)
{
PageSizeTextLabel.Visibility = ShowPageSize ? Visibility.Visible : Visibility.Collapsed;
PageSizeLabel.Visibility = ShowPageSize ? Visibility.Visible : Visibility.Collapsed;
}
}
private void CurrentPageTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
BindingExpression bindingExpression = ((TextBox)sender).GetBindingExpression(TextBox.TextProperty);
if (bindingExpression != null)
bindingExpression.UpdateSource();
}
}
#endregion
}
}