using ImTools; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Diagnostics; 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 { /// /// WritableComboBox.xaml 的交互逻辑 /// public partial class WritableComboBox : UserControl { public bool IsCurrentPage { get { return (bool)GetValue(IsCurrentPageProperty); } set { SetValue(IsCurrentPageProperty, value); } } // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc... public static readonly DependencyProperty IsCurrentPageProperty = DependencyProperty.Register("IsCurrentPage", typeof(bool), typeof(WritableComboBox), new PropertyMetadata(false)); public Visibility IsAllPageVisible { get { return (Visibility)GetValue(IsAllPageVisibleProperty); } set { SetValue(IsAllPageVisibleProperty, value); } } // Using a DependencyProperty as the backing store for IsAllPageVisible. This enables animation, styling, binding, etc... public static readonly DependencyProperty IsAllPageVisibleProperty = DependencyProperty.Register("IsAllPageVisible", typeof(Visibility), typeof(WritableComboBox), new PropertyMetadata(Visibility.Visible, (d, e) => { if ((Visibility)e.NewValue != Visibility.Visible) { (d as WritableComboBox).SetIndexByVisiblity((Visibility)e.NewValue); } })); private void SetIndexByVisiblity(Visibility visible) { writableComboBox.SelectedIndex = 1; } public bool CurrentPage { get { return (bool)GetValue(CurrentPageProperty); } set { SetValue(CurrentPageProperty, value); } } // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc... public static readonly DependencyProperty CurrentPageProperty = DependencyProperty.Register("CurrentPage", typeof(bool), typeof(WritableComboBox), new PropertyMetadata(false)); public bool EvenPageIsEnabled { get { return (bool)GetValue(EvenPageIsEnabledProperty); } set { SetValue(EvenPageIsEnabledProperty, value); } } // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc... public static readonly DependencyProperty EvenPageIsEnabledProperty = DependencyProperty.Register("EvenPageIsEnabled", typeof(bool), typeof(WritableComboBox), new PropertyMetadata(true)); public string SelectedIndex { get { return (string)GetValue(SelectedIndexProperty); } set { SetValue(SelectedIndexProperty, value); } } // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc... public static readonly DependencyProperty SelectedIndexProperty = DependencyProperty.Register("SelectedIndex", typeof(string), typeof(WritableComboBox), new PropertyMetadata("0")); public string Text { get { return (string)GetValue(TextProperty); } set { SetValue(TextProperty, value); } } // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc... public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(WritableComboBox), new PropertyMetadata("")); public ItemCollection Items { get { return (ItemCollection)GetValue(ItemsProperty); } set { SetValue(ItemsProperty, value); } } public static readonly DependencyProperty ItemsProperty = DependencyProperty.Register("Items", typeof(ItemCollection), typeof(WritableComboBox), new PropertyMetadata()); /// /// 把子控件的事件传递出去,方便绑定 /// public event RoutedEventHandler SelectionChanged; /// /// 把子控件的事件传递出去,方便绑定 /// public event RoutedEventHandler TextChanged; public WritableComboBox() { InitializeComponent(); this.Items = this.writableComboBox.Items; } private void writableComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (this.writableComboBox.SelectedIndex == this.writableComboBox.Items.Count - 1) { if (this.writableComboBox.ActualWidth == 0) { this.writableTextBox.Width = 210; this.writableTextBox.Visibility = Visibility.Visible; return; } this.writableTextBox.Width = this.writableComboBox.ActualWidth - 18; Trace.WriteLine(this.writableComboBox.ActualWidth); this.writableTextBox.Visibility = Visibility.Visible; } else { if (this.writableTextBox != null) { this.writableTextBox.Visibility = Visibility.Hidden; } } if (this.writableComboBox.Items.Count == 5) { if (this.writableComboBox.SelectedIndex == 1) { IsCurrentPage = true; } else { IsCurrentPage = false; } } this.SelectedIndex = this.writableComboBox.SelectedIndex.ToString(); SelectionChanged?.Invoke(sender, e); } private void writableTextBox_TextChange(object sender, TextChangedEventArgs e) { if (this.writableComboBox.SelectedIndex == this.writableComboBox.Items.Count - 1) { Text = this.writableTextBox.Text; } else { Text = ""; } TextChanged?.Invoke(sender, e); } } }