|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using System.Windows; |
| 7 | +using System.Windows.Controls; |
| 8 | +using System.Windows.Data; |
| 9 | +using System.Windows.Documents; |
| 10 | +using System.Windows.Input; |
| 11 | +using System.Windows.Media; |
| 12 | +using System.Windows.Media.Imaging; |
| 13 | +using System.Windows.Navigation; |
| 14 | +using System.Windows.Shapes; |
| 15 | + |
| 16 | + |
| 17 | +namespace CustomControlSample { |
| 18 | + |
| 19 | + |
| 20 | + /// <summary> |
| 21 | + /// Interaction logic for MainWindow.xaml |
| 22 | + /// </summary> |
| 23 | + public partial class MainWindow: Window { |
| 24 | + public MainWindow() { |
| 25 | + InitializeComponent(); |
| 26 | + |
| 27 | + TestCustomControlSample.FontSize = toInt(FontSizeTextBox); |
| 28 | + FontSizeTextBox.LostFocus += fontSizeTextBox_LostFocus; |
| 29 | + FontsizeScrollBar.Value = toInt(FontSizeTextBox); |
| 30 | + FontsizeScrollBar.Scroll += fontsizeScrollBar_Scroll; |
| 31 | + |
| 32 | + HorizontalAlignmentComboBox.Items.Add(new ComboBoxItem { Content= "Left", Tag=HorizontalAlignment.Left, IsSelected=true }); |
| 33 | + HorizontalAlignmentComboBox.Items.Add(new ComboBoxItem { Content= "Center", Tag=HorizontalAlignment.Center }); |
| 34 | + HorizontalAlignmentComboBox.Items.Add(new ComboBoxItem { Content= "Right", Tag=HorizontalAlignment.Right }); |
| 35 | + HorizontalAlignmentComboBox.Items.Add(new ComboBoxItem { Content= "Stretch", Tag=HorizontalAlignment.Stretch }); |
| 36 | + TestCustomControlSample.HorizontalAlignment = HorizontalAlignment.Left; |
| 37 | + HorizontalAlignmentComboBox.SelectionChanged += horizontalAlignmentComboBox_SelectionChanged; |
| 38 | + |
| 39 | + VerticalAlignmentComboBox.Items.Add(new ComboBoxItem { Content= "Top", Tag=VerticalAlignment.Top, IsSelected=true }); |
| 40 | + VerticalAlignmentComboBox.Items.Add(new ComboBoxItem { Content= "Center", Tag=VerticalAlignment.Center }); |
| 41 | + VerticalAlignmentComboBox.Items.Add(new ComboBoxItem { Content= "Bottom", Tag=VerticalAlignment.Bottom }); |
| 42 | + VerticalAlignmentComboBox.Items.Add(new ComboBoxItem { Content= "Stretch", Tag=VerticalAlignment.Stretch }); |
| 43 | + TestCustomControlSample.VerticalAlignment = VerticalAlignment.Top; |
| 44 | + VerticalAlignmentComboBox.SelectionChanged += verticalAlignmentComboBox_SelectionChanged; |
| 45 | + } |
| 46 | + |
| 47 | + |
| 48 | + private double toInt(TextBox textBox) { |
| 49 | + if (int.TryParse(textBox.Text, out var result)) { |
| 50 | + return result; |
| 51 | + } |
| 52 | + return 20; |
| 53 | + } |
| 54 | + |
| 55 | + private void fontSizeTextBox_LostFocus(object sender, RoutedEventArgs e) { |
| 56 | + var newValue = toInt(FontSizeTextBox); |
| 57 | + //if (newValue) { |
| 58 | + |
| 59 | + //} |
| 60 | + TestCustomControlSample.FontSize = newValue; |
| 61 | + FontsizeScrollBar.Value = newValue; |
| 62 | + } |
| 63 | + |
| 64 | + |
| 65 | + private void fontsizeScrollBar_Scroll(object sender, System.Windows.Controls.Primitives.ScrollEventArgs e) { |
| 66 | + FontSizeTextBox.Text = ((int)FontsizeScrollBar.Value).ToString(); |
| 67 | + TestCustomControlSample.FontSize = (int)FontsizeScrollBar.Value; |
| 68 | + } |
| 69 | + |
| 70 | + |
| 71 | + private void horizontalAlignmentComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { |
| 72 | + TestCustomControlSample.HorizontalAlignment = (HorizontalAlignment)((ComboBoxItem)HorizontalAlignmentComboBox.SelectedItem).Tag; |
| 73 | + } |
| 74 | + |
| 75 | + private void verticalAlignmentComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { |
| 76 | + TestCustomControlSample.VerticalAlignment = (VerticalAlignment)((ComboBoxItem)VerticalAlignmentComboBox.SelectedItem).Tag; |
| 77 | + } |
| 78 | + } |
| 79 | +} |
0 commit comments