using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace PDF_Office.CustomControl { /// /// PaginationControl.xaml 的交互逻辑 /// public partial class PaginationControl : UserControl { public PaginationControl() { InitializeComponent(); } public int CurrentPage { get { return (int)GetValue(CurrentPageProperty); } set { SetValue(CurrentPageProperty, value); } } // Using a DependencyProperty as the backing store for CurrentPage. This enables animation, styling, binding, etc... public static readonly DependencyProperty CurrentPageProperty = DependencyProperty.Register("CurrentPage", typeof(int), typeof(PaginationControl), new PropertyMetadata(0)); public int PageCount { get { return (int)GetValue(PageCountProperty); } set { SetValue(PageCountProperty, value); } } // Using a DependencyProperty as the backing store for PageCount. This enables animation, styling, binding, etc... public static readonly DependencyProperty PageCountProperty = DependencyProperty.Register("PageCount", typeof(int), typeof(PaginationControl), new PropertyMetadata(0)); public string InputString { get { return (string)GetValue(InputStringProperty); } set { SetValue(InputStringProperty, value); } } // Using a DependencyProperty as the backing store for InputString. This enables animation, styling, binding, etc... public static readonly DependencyProperty InputStringProperty = DependencyProperty.Register("InputString", typeof(string), typeof(PaginationControl), new PropertyMetadata("")); private void CheckInput() { int page = CurrentPage; bool result = int.TryParse(InputString,out page); if(result&&(page <= PageCount)&&page>=1) { CurrentPage = page; } else { InputString = CurrentPage.ToString(); } } private async void TblIndex_PreviewMouseDown(object sender, MouseButtonEventArgs e) { if(e.ClickCount==2) { TblIndex.Visibility = Visibility.Collapsed; TxtInput.Visibility = Visibility.Visible; await Task.Delay(20); TxtInput.SelectAll(); TxtInput.Focus(); InputString = CurrentPage.ToString(); } } private void TxtInput_LostFocus(object sender, RoutedEventArgs e) { CheckInput(); TblIndex.Visibility = Visibility.Visible; TxtInput.Visibility = Visibility.Collapsed; } private void TxtInput_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { CheckInput(); } } } }