using System; using System.Collections.Generic; using System.ComponentModel; 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 compdfkit_tools.Common { /// /// CPDFFontUI.xaml 的交互逻辑 /// public partial class CPDFFontUI : UserControl, INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public event EventHandler FontChanged; public string FontFamilyValue { get => FontFamilyComboBox.SelectedItem.ToString(); } public bool IsBold { get { if (FontStyleComboBox.SelectedItem.ToString() == null || (FontStyleComboBox.SelectedItem.ToString() == "Italic")) { return false; } else { return true; } } } public bool IsItalic { get { if (FontStyleComboBox.SelectedItem.ToString() == null || (FontStyleComboBox.SelectedItem.ToString() == "Bold")) { return false; } else { return true; } } } public TextAlignment TextAlignment { get { if ((bool)LeftAlignRadioButton.IsChecked) { return TextAlignment.Left; } else if ((bool)CenterAlignRadioButton.IsChecked) { return TextAlignment.Center; } else { return TextAlignment.Right; } } } private int _fontSizeValue = 20; public int FontSizeValue { get => _fontSizeValue; set { _fontSizeValue = value; OnPropertyChanged(nameof(FontSizeValue)); OnFontChanged(); FontChanged?.Invoke(this, EventArgs.Empty); } } public CPDFFontUI() { InitializeComponent(); InitComboBox(); this.DataContext = this; } public void InitComboBox() { List fontNameList = new List() { {"Courier New" }, {"Helvetica" }, {"Times Roman" } }; FontFamilyComboBox.ItemsSource = fontNameList; FontFamilyComboBox.SelectedIndex = 1; List fontStyleList = new List() { {"Common" }, {"Bold" }, {"Italic" }, {"Bold and Italic" } }; FontStyleComboBox.ItemsSource = fontStyleList; FontStyleComboBox.SelectedIndex = 0; List fontSizeList = new List() { {6}, {8}, {9}, {10}, {12}, {14}, {18}, {20}, {24}, {26}, {28}, {32}, {30}, {32}, {48}, {72} }; FontSizeComboBox.InitPresetNumberArray(fontSizeList); } protected void OnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } private void FontFamilyComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { FontChanged?.Invoke(this, EventArgs.Empty); } private void FontStyleComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { FontChanged?.Invoke(this, EventArgs.Empty); } private void AlignRadioButton_Checked(object sender, RoutedEventArgs e) { FontChanged?.Invoke(this, EventArgs.Empty); } private void OnFontChanged() { FontChanged?.Invoke(this, EventArgs.Empty); } } }