// helper method for ctor void TBWLAddToGrid(ref TextBoxWithLister box, ref Grid grid, int col, string caption) { if (box != null) { throw new ArgumentException("box var = null"); } // create Label Label lbl = new Label() { Content = caption, Margin = new Thickness(12, 12, 12, 0) }; grid.Children.Add(lbl); Grid.SetRow(lbl, 0); Grid.SetColumn(lbl, col); // create Caption box = new TextBoxWithLister() { IsReadOnly = true, Margin = new Thickness(12, 0, 12, 12) }; grid.Children.Add(box); Grid.SetRow(box, 1); Grid.SetColumn(box, col); }
public FontDialog() { Title = "Font"; ShowInTaskbar = false; WindowStyle = WindowStyle.ToolWindow; WindowStartupLocation = WindowStartupLocation.CenterOwner; SizeToContent = SizeToContent.WidthAndHeight; ResizeMode = ResizeMode.NoResize; Grid gridMain = new Grid(); Content = gridMain; RowDefinition rowdef = new RowDefinition(); rowdef.Height = new GridLength(200, GridUnitType.Pixel); gridMain.RowDefinitions.Add(rowdef); rowdef = new RowDefinition(); rowdef.Height = new GridLength(150, GridUnitType.Pixel); gridMain.RowDefinitions.Add(rowdef); ColumnDefinition coldef = new ColumnDefinition(); coldef.Width = new GridLength(650, GridUnitType.Pixel); gridMain.ColumnDefinitions.Add(coldef); Grid gridBoxes = new Grid(); gridMain.Children.Add(gridBoxes); rowdef = new RowDefinition(); rowdef.Height = GridLength.Auto; gridBoxes.RowDefinitions.Add(rowdef); rowdef = new RowDefinition(); rowdef.Height = new GridLength(100, GridUnitType.Star); gridBoxes.RowDefinitions.Add(rowdef); coldef = new ColumnDefinition(); coldef.Width = new GridLength(175, GridUnitType.Star); gridBoxes.ColumnDefinitions.Add(coldef); coldef = new ColumnDefinition(); coldef.Width = new GridLength(100, GridUnitType.Star); gridBoxes.ColumnDefinitions.Add(coldef); coldef = new ColumnDefinition(); coldef.Width = new GridLength(100, GridUnitType.Star); gridBoxes.ColumnDefinitions.Add(coldef); coldef = new ColumnDefinition(); coldef.Width = new GridLength(100, GridUnitType.Star); gridBoxes.ColumnDefinitions.Add(coldef); coldef = new ColumnDefinition(); coldef.Width = new GridLength(75, GridUnitType.Star); gridBoxes.ColumnDefinitions.Add(coldef); Label lbl = new Label(); lbl.Content = "Font Family"; lbl.Margin = new Thickness(12, 12, 12, 0); gridBoxes.Children.Add(lbl); Grid.SetRow(lbl, 0); Grid.SetColumn(lbl, 0); boxFamily = new TextBoxWithLister(); boxFamily.IsReadOnly = true; boxFamily.Margin = new Thickness(12, 0, 12, 12); gridBoxes.Children.Add(boxFamily); Grid.SetRow(boxFamily, 1); Grid.SetColumn(boxFamily, 0); lbl = new Label(); lbl.Content = "Style"; lbl.Margin = new Thickness(12,12,12,0); gridBoxes.Children.Add(lbl); Grid.SetRow(lbl, 0); Grid.SetColumn(lbl, 1); boxStyle = new TextBoxWithLister(); boxStyle.IsReadOnly = true; boxStyle.Margin = new Thickness(12, 0, 12, 12); gridBoxes.Children.Add(boxStyle); Grid.SetRow(boxStyle, 1); Grid.SetColumn(boxStyle, 1); lbl = new Label(); lbl.Content = "Weight"; lbl.Margin = new Thickness(12, 12, 12, 0); gridBoxes.Children.Add(lbl); Grid.SetRow(lbl, 0); Grid.SetColumn(lbl, 2); boxWeight = new TextBoxWithLister(); boxWeight.IsReadOnly = true; boxWeight.Margin = new Thickness(12, 0, 12, 12); gridBoxes.Children.Add(boxWeight); Grid.SetRow(boxWeight, 1); Grid.SetColumn(boxWeight, 2); lbl = new Label(); lbl.Content = "Stretch"; lbl.Margin = new Thickness(12, 12, 12, 0); gridBoxes.Children.Add(lbl); Grid.SetRow(lbl, 0); Grid.SetColumn(lbl, 3); boxStretch = new TextBoxWithLister(); boxStretch.IsReadOnly = true; boxStretch.Margin = new Thickness(12, 0, 12, 12); gridBoxes.Children.Add(boxStretch); Grid.SetRow(boxStretch, 1); Grid.SetColumn(boxStretch, 3); lbl = new Label(); lbl.Content = "Size"; lbl.Margin = new Thickness(12, 12, 12, 0); gridBoxes.Children.Add(lbl); Grid.SetRow(lbl, 0); Grid.SetColumn(lbl, 4); boxSize = new TextBoxWithLister(); boxSize.Margin = new Thickness(12, 0, 12, 12); gridBoxes.Children.Add(boxSize); Grid.SetRow(boxSize, 1); Grid.SetColumn(boxSize, 4); lblDisplay = new Label(); lblDisplay.Content = "AbBbCC XxYyZz 012345"; lblDisplay.HorizontalContentAlignment = HorizontalAlignment.Center; lblDisplay.VerticalContentAlignment = VerticalAlignment.Center; gridMain.Children.Add(lblDisplay); Grid.SetRow(lblDisplay, 1); Grid gridButtons = new Grid(); gridMain.Children.Add(gridButtons); Grid.SetRow(gridButtons, 2); for (int i = 0; i < 5; i++) gridButtons.ColumnDefinitions.Add(new ColumnDefinition()); Button btn = new Button(); btn.Content = "OK"; btn.IsDefault = true; btn.HorizontalAlignment = HorizontalAlignment.Center; btn.MinWidth = 60; btn.Margin = new Thickness(12); btn.Click += OkOnClick; gridButtons.Children.Add(btn); Grid.SetColumn(btn, 1); btn = new Button(); btn.Content = "Cancel"; btn.IsCancel = true; btn.HorizontalAlignment = HorizontalAlignment.Center; btn.MinWidth = 60; btn.Margin = new Thickness(12); gridButtons.Children.Add(btn); Grid.SetColumn(btn, 3); foreach (FontFamily fam in Fonts.SystemFontFamilies) boxFamily.Add(fam); double[] ptsizes = new double[] { 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72 }; foreach (double ptsize in ptsizes) boxSize.Add(ptsize); boxFamily.SelectionChanged += FamilyOnSelectionChanged; boxStyle.SelectionChanged += StyleOnSelectionChanged; boxWeight.SelectionChanged += StyleOnSelectionChanged; boxStretch.SelectionChanged += StyleOnSelectionChanged; boxSize.TextChanged += SizeOnTextChanged; Typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch); FaceSize = FontSize; boxFamily.Focus(); isUpdateSuppressed = false; UpdateSample(); }
// Constructor. public FontDialog() { Title = "Font"; ShowInTaskbar = false; WindowStyle = WindowStyle.ToolWindow; WindowStartupLocation = WindowStartupLocation.CenterOwner; SizeToContent = SizeToContent.WidthAndHeight; ResizeMode = ResizeMode.NoResize; // Create three-row Grid as content of window. Grid gridMain = new Grid(); Content = gridMain; // This row is for the TextBoxWithLister controls. RowDefinition rowdef = new RowDefinition(); rowdef.Height = new GridLength(200, GridUnitType.Pixel); gridMain.RowDefinitions.Add(rowdef); // This row is for the sample text. rowdef = new RowDefinition(); rowdef.Height = new GridLength(150, GridUnitType.Pixel); gridMain.RowDefinitions.Add(rowdef); // This row is for the buttons. rowdef = new RowDefinition(); rowdef.Height = GridLength.Auto; gridMain.RowDefinitions.Add(rowdef); // One column in main Grid. ColumnDefinition coldef = new ColumnDefinition(); coldef.Width = new GridLength(650, GridUnitType.Pixel); gridMain.ColumnDefinitions.Add(coldef); // Create two-row, five-column Grid for TextBoxWithLister controls. Grid gridBoxes = new Grid(); gridMain.Children.Add(gridBoxes); // This row is for the labels. rowdef = new RowDefinition(); rowdef.Height = GridLength.Auto; gridBoxes.RowDefinitions.Add(rowdef); // This row is for the EditBoxWithLister controls. rowdef = new RowDefinition(); rowdef.Height = new GridLength(100, GridUnitType.Star); gridBoxes.RowDefinitions.Add(rowdef); // First column is FontFamily. coldef = new ColumnDefinition(); coldef.Width = new GridLength(175, GridUnitType.Star); gridBoxes.ColumnDefinitions.Add(coldef); // Second column is FontStyle. coldef = new ColumnDefinition(); coldef.Width = new GridLength(100, GridUnitType.Star); gridBoxes.ColumnDefinitions.Add(coldef); // Third column is FontWeight. coldef = new ColumnDefinition(); coldef.Width = new GridLength(100, GridUnitType.Star); gridBoxes.ColumnDefinitions.Add(coldef); // Fourth column is FontStretch. coldef = new ColumnDefinition(); coldef.Width = new GridLength(100, GridUnitType.Star); gridBoxes.ColumnDefinitions.Add(coldef); // Fifth column is Size. coldef = new ColumnDefinition(); coldef.Width = new GridLength(75, GridUnitType.Star); gridBoxes.ColumnDefinitions.Add(coldef); // Create FontFamily labels and TextBoxWithLister controls. Label lbl = new Label(); lbl.Content = "Font Family"; lbl.Margin = new Thickness(12, 12, 12, 0); gridBoxes.Children.Add(lbl); Grid.SetRow(lbl, 0); Grid.SetColumn(lbl, 0); boxFamily = new TextBoxWithLister(); boxFamily.IsReadOnly = true; boxFamily.Margin = new Thickness(12, 0, 12, 12); gridBoxes.Children.Add(boxFamily); Grid.SetRow(boxFamily, 1); Grid.SetColumn(boxFamily, 0); // Create FontStyle labels and TextBoxWithLister controls. lbl = new Label(); lbl.Content = "Style"; lbl.Margin = new Thickness(12, 12, 12, 0); gridBoxes.Children.Add(lbl); Grid.SetRow(lbl, 0); Grid.SetColumn(lbl, 1); boxStyle = new TextBoxWithLister(); boxStyle.IsReadOnly = true; boxStyle.Margin = new Thickness(12, 0, 12, 12); gridBoxes.Children.Add(boxStyle); Grid.SetRow(boxStyle, 1); Grid.SetColumn(boxStyle, 1); // Create FontWeight labels and TextBoxWithLister controls. lbl = new Label(); lbl.Content = "Weight"; lbl.Margin = new Thickness(12, 12, 12, 0); gridBoxes.Children.Add(lbl); Grid.SetRow(lbl, 0); Grid.SetColumn(lbl, 2); boxWeight = new TextBoxWithLister(); boxWeight.IsReadOnly = true; boxWeight.Margin = new Thickness(12, 0, 12, 12); gridBoxes.Children.Add(boxWeight); Grid.SetRow(boxWeight, 1); Grid.SetColumn(boxWeight, 2); // Create FontStretch labels and TextBoxWithLister controls. lbl = new Label(); lbl.Content = "Stretch"; lbl.Margin = new Thickness(12, 12, 12, 0); gridBoxes.Children.Add(lbl); Grid.SetRow(lbl, 0); Grid.SetColumn(lbl, 3); boxStretch = new TextBoxWithLister(); boxStretch.IsReadOnly = true; boxStretch.Margin = new Thickness(12, 0, 12, 12); gridBoxes.Children.Add(boxStretch); Grid.SetRow(boxStretch, 1); Grid.SetColumn(boxStretch, 3); // Create Size labels and TextBoxWithLister controls. lbl = new Label(); lbl.Content = "Size"; lbl.Margin = new Thickness(12, 12, 12, 0); gridBoxes.Children.Add(lbl); Grid.SetRow(lbl, 0); Grid.SetColumn(lbl, 4); boxSize = new TextBoxWithLister(); boxSize.Margin = new Thickness(12, 0, 12, 12); gridBoxes.Children.Add(boxSize); Grid.SetRow(boxSize, 1); Grid.SetColumn(boxSize, 4); // Create Label to display sample text. lblDisplay = new Label(); lblDisplay.Content = "AaBbCc XxYzZz 012345"; lblDisplay.HorizontalContentAlignment = HorizontalAlignment.Center; lblDisplay.VerticalContentAlignment = VerticalAlignment.Center; gridMain.Children.Add(lblDisplay); Grid.SetRow(lblDisplay, 1); // Create five-column Grid for Buttons. Grid gridButtons = new Grid(); gridMain.Children.Add(gridButtons); Grid.SetRow(gridButtons, 2); for (int i = 0; i < 5; i++) gridButtons.ColumnDefinitions.Add(new ColumnDefinition()); // OK button. Button btn = new Button(); btn.Content = "OK"; btn.IsDefault = true; btn.HorizontalAlignment = HorizontalAlignment.Center; btn.MinWidth = 60; btn.Margin = new Thickness(12); btn.Click += OkOnClick; gridButtons.Children.Add(btn); Grid.SetColumn(btn, 1); // Cancel button. btn = new Button(); btn.Content = "Cancel"; btn.IsCancel = true; btn.HorizontalAlignment = HorizontalAlignment.Center; btn.MinWidth = 60; btn.Margin = new Thickness(12); gridButtons.Children.Add(btn); Grid.SetColumn(btn, 3); // Initialize FontFamily box with system font families. foreach (FontFamily fam in Fonts.SystemFontFamilies) boxFamily.Add(fam); // Initialize FontSize box. double[] ptsizes = new double[] { 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72 }; foreach (double ptsize in ptsizes) boxSize.Add(ptsize); // Set event handlers. boxFamily.SelectionChanged += FamilyOnSelectionChanged; boxStyle.SelectionChanged += StyleOnSelectionChanged; boxWeight.SelectionChanged += StyleOnSelectionChanged; boxStretch.SelectionChanged += StyleOnSelectionChanged; boxSize.TextChanged += SizeOnTextChanged; // Initialize selected values based on Window properties. // (These will probably be overridden when properties are set.) Typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch); FaceSize = FontSize; // Set keyboard focus. boxFamily.Focus(); // Allow updates to the sample text. isUpdateSuppressed = false; UpdateSample(); }
public FontDialog() { Title = "Font"; ShowInTaskbar = false; WindowStyle = WindowStyle.ToolWindow; WindowStartupLocation = WindowStartupLocation.CenterOwner; SizeToContent = SizeToContent.WidthAndHeight; ResizeMode = ResizeMode.NoResize; Grid gridMain = new Grid(); Content = gridMain; RowDefinition rowdef = new RowDefinition(); rowdef.Height = new GridLength(200, GridUnitType.Pixel); gridMain.RowDefinitions.Add(rowdef); rowdef = new RowDefinition(); rowdef.Height = new GridLength(150, GridUnitType.Pixel); gridMain.RowDefinitions.Add(rowdef); ColumnDefinition coldef = new ColumnDefinition(); coldef.Width = new GridLength(650, GridUnitType.Pixel); gridMain.ColumnDefinitions.Add(coldef); Grid gridBoxes = new Grid(); gridMain.Children.Add(gridBoxes); rowdef = new RowDefinition(); rowdef.Height = GridLength.Auto; gridBoxes.RowDefinitions.Add(rowdef); rowdef = new RowDefinition(); rowdef.Height = new GridLength(100, GridUnitType.Star); gridBoxes.RowDefinitions.Add(rowdef); coldef = new ColumnDefinition(); coldef.Width = new GridLength(175, GridUnitType.Star); gridBoxes.ColumnDefinitions.Add(coldef); coldef = new ColumnDefinition(); coldef.Width = new GridLength(100, GridUnitType.Star); gridBoxes.ColumnDefinitions.Add(coldef); coldef = new ColumnDefinition(); coldef.Width = new GridLength(100, GridUnitType.Star); gridBoxes.ColumnDefinitions.Add(coldef); coldef = new ColumnDefinition(); coldef.Width = new GridLength(100, GridUnitType.Star); gridBoxes.ColumnDefinitions.Add(coldef); coldef = new ColumnDefinition(); coldef.Width = new GridLength(75, GridUnitType.Star); gridBoxes.ColumnDefinitions.Add(coldef); Label lbl = new Label(); lbl.Content = "Font Family"; lbl.Margin = new Thickness(12, 12, 12, 0); gridBoxes.Children.Add(lbl); Grid.SetRow(lbl, 0); Grid.SetColumn(lbl, 0); boxFamily = new TextBoxWithLister(); boxFamily.IsReadOnly = true; boxFamily.Margin = new Thickness(12, 0, 12, 12); gridBoxes.Children.Add(boxFamily); Grid.SetRow(boxFamily, 1); Grid.SetColumn(boxFamily, 0); lbl = new Label(); lbl.Content = "Style"; lbl.Margin = new Thickness(12, 12, 12, 0); gridBoxes.Children.Add(lbl); Grid.SetRow(lbl, 0); Grid.SetColumn(lbl, 1); boxStyle = new TextBoxWithLister(); boxStyle.IsReadOnly = true; boxStyle.Margin = new Thickness(12, 0, 12, 12); gridBoxes.Children.Add(boxStyle); Grid.SetRow(boxStyle, 1); Grid.SetColumn(boxStyle, 1); lbl = new Label(); lbl.Content = "Weight"; lbl.Margin = new Thickness(12, 12, 12, 0); gridBoxes.Children.Add(lbl); Grid.SetRow(lbl, 0); Grid.SetColumn(lbl, 2); boxWeight = new TextBoxWithLister(); boxWeight.IsReadOnly = true; boxWeight.Margin = new Thickness(12, 0, 12, 12); gridBoxes.Children.Add(boxWeight); Grid.SetRow(boxWeight, 1); Grid.SetColumn(boxWeight, 2); lbl = new Label(); lbl.Content = "Stretch"; lbl.Margin = new Thickness(12, 12, 12, 0); gridBoxes.Children.Add(lbl); Grid.SetRow(lbl, 0); Grid.SetColumn(lbl, 3); boxStretch = new TextBoxWithLister(); boxStretch.IsReadOnly = true; boxStretch.Margin = new Thickness(12, 0, 12, 12); gridBoxes.Children.Add(boxStretch); Grid.SetRow(boxStretch, 1); Grid.SetColumn(boxStretch, 3); lbl = new Label(); lbl.Content = "Size"; lbl.Margin = new Thickness(12, 12, 12, 0); gridBoxes.Children.Add(lbl); Grid.SetRow(lbl, 0); Grid.SetColumn(lbl, 4); boxSize = new TextBoxWithLister(); boxSize.Margin = new Thickness(12, 0, 12, 12); gridBoxes.Children.Add(boxSize); Grid.SetRow(boxSize, 1); Grid.SetColumn(boxSize, 4); lblDisplay = new Label(); lblDisplay.Content = "AbBbCC XxYyZz 012345"; lblDisplay.HorizontalContentAlignment = HorizontalAlignment.Center; lblDisplay.VerticalContentAlignment = VerticalAlignment.Center; gridMain.Children.Add(lblDisplay); Grid.SetRow(lblDisplay, 1); Grid gridButtons = new Grid(); gridMain.Children.Add(gridButtons); Grid.SetRow(gridButtons, 2); for (int i = 0; i < 5; i++) { gridButtons.ColumnDefinitions.Add(new ColumnDefinition()); } Button btn = new Button(); btn.Content = "OK"; btn.IsDefault = true; btn.HorizontalAlignment = HorizontalAlignment.Center; btn.MinWidth = 60; btn.Margin = new Thickness(12); btn.Click += OkOnClick; gridButtons.Children.Add(btn); Grid.SetColumn(btn, 1); btn = new Button(); btn.Content = "Cancel"; btn.IsCancel = true; btn.HorizontalAlignment = HorizontalAlignment.Center; btn.MinWidth = 60; btn.Margin = new Thickness(12); gridButtons.Children.Add(btn); Grid.SetColumn(btn, 3); foreach (FontFamily fam in Fonts.SystemFontFamilies) { boxFamily.Add(fam); } double[] ptsizes = new double[] { 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72 }; foreach (double ptsize in ptsizes) { boxSize.Add(ptsize); } boxFamily.SelectionChanged += FamilyOnSelectionChanged; boxStyle.SelectionChanged += StyleOnSelectionChanged; boxWeight.SelectionChanged += StyleOnSelectionChanged; boxStretch.SelectionChanged += StyleOnSelectionChanged; boxSize.TextChanged += SizeOnTextChanged; Typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch); FaceSize = FontSize; boxFamily.Focus(); isUpdateSuppressed = false; UpdateSample(); }
// Constructor. public FontDialog() { Title = "Font"; ShowInTaskbar = false; WindowStyle = WindowStyle.ToolWindow; WindowStartupLocation = WindowStartupLocation.CenterOwner; SizeToContent = SizeToContent.WidthAndHeight; ResizeMode = ResizeMode.NoResize; // Create three-row Grid as content of window. Grid gridMain = new Grid(); Content = gridMain; // This row is for the TextBoxWithLister controls. RowDefinition rowdef = new RowDefinition(); rowdef.Height = new GridLength(200, GridUnitType.Pixel); gridMain.RowDefinitions.Add(rowdef); // This row is for the sample text. rowdef = new RowDefinition(); rowdef.Height = new GridLength(150, GridUnitType.Pixel); gridMain.RowDefinitions.Add(rowdef); // This row is for the buttons. rowdef = new RowDefinition(); rowdef.Height = GridLength.Auto; gridMain.RowDefinitions.Add(rowdef); // One column in main Grid. ColumnDefinition coldef = new ColumnDefinition(); coldef.Width = new GridLength(650, GridUnitType.Pixel); gridMain.ColumnDefinitions.Add(coldef); // Create two-row, five-column Grid for TextBoxWithLister controls. Grid gridBoxes = new Grid(); gridMain.Children.Add(gridBoxes); // This row is for the labels. rowdef = new RowDefinition(); rowdef.Height = GridLength.Auto; gridBoxes.RowDefinitions.Add(rowdef); // This row is for the EditBoxWithLister controls. rowdef = new RowDefinition(); rowdef.Height = new GridLength(100, GridUnitType.Star); gridBoxes.RowDefinitions.Add(rowdef); // First column is FontFamily. coldef = new ColumnDefinition(); coldef.Width = new GridLength(175, GridUnitType.Star); gridBoxes.ColumnDefinitions.Add(coldef); // Second column is FontStyle. coldef = new ColumnDefinition(); coldef.Width = new GridLength(100, GridUnitType.Star); gridBoxes.ColumnDefinitions.Add(coldef); // Third column is FontWeight. coldef = new ColumnDefinition(); coldef.Width = new GridLength(100, GridUnitType.Star); gridBoxes.ColumnDefinitions.Add(coldef); // Fourth column is FontStretch. coldef = new ColumnDefinition(); coldef.Width = new GridLength(100, GridUnitType.Star); gridBoxes.ColumnDefinitions.Add(coldef); // Fifth column is Size. coldef = new ColumnDefinition(); coldef.Width = new GridLength(75, GridUnitType.Star); gridBoxes.ColumnDefinitions.Add(coldef); // Create FontFamily labels and TextBoxWithLister controls. Label lbl = new Label(); lbl.Content = "Font Family"; lbl.Margin = new Thickness(12, 12, 12, 0); gridBoxes.Children.Add(lbl); Grid.SetRow(lbl, 0); Grid.SetColumn(lbl, 0); boxFamily = new TextBoxWithLister(); boxFamily.IsReadOnly = true; boxFamily.Margin = new Thickness(12, 0, 12, 12); gridBoxes.Children.Add(boxFamily); Grid.SetRow(boxFamily, 1); Grid.SetColumn(boxFamily, 0); // Create FontStyle labels and TextBoxWithLister controls. lbl = new Label(); lbl.Content = "Style"; lbl.Margin = new Thickness(12, 12, 12, 0); gridBoxes.Children.Add(lbl); Grid.SetRow(lbl, 0); Grid.SetColumn(lbl, 1); boxStyle = new TextBoxWithLister(); boxStyle.IsReadOnly = true; boxStyle.Margin = new Thickness(12, 0, 12, 12); gridBoxes.Children.Add(boxStyle); Grid.SetRow(boxStyle, 1); Grid.SetColumn(boxStyle, 1); // Create FontWeight labels and TextBoxWithLister controls. lbl = new Label(); lbl.Content = "Weight"; lbl.Margin = new Thickness(12, 12, 12, 0); gridBoxes.Children.Add(lbl); Grid.SetRow(lbl, 0); Grid.SetColumn(lbl, 2); boxWeight = new TextBoxWithLister(); boxWeight.IsReadOnly = true; boxWeight.Margin = new Thickness(12, 0, 12, 12); gridBoxes.Children.Add(boxWeight); Grid.SetRow(boxWeight, 1); Grid.SetColumn(boxWeight, 2); // Create FontStretch labels and TextBoxWithLister controls. lbl = new Label(); lbl.Content = "Stretch"; lbl.Margin = new Thickness(12, 12, 12, 0); gridBoxes.Children.Add(lbl); Grid.SetRow(lbl, 0); Grid.SetColumn(lbl, 3); boxStretch = new TextBoxWithLister(); boxStretch.IsReadOnly = true; boxStretch.Margin = new Thickness(12, 0, 12, 12); gridBoxes.Children.Add(boxStretch); Grid.SetRow(boxStretch, 1); Grid.SetColumn(boxStretch, 3); // Create Size labels and TextBoxWithLister controls. lbl = new Label(); lbl.Content = "Size"; lbl.Margin = new Thickness(12, 12, 12, 0); gridBoxes.Children.Add(lbl); Grid.SetRow(lbl, 0); Grid.SetColumn(lbl, 4); boxSize = new TextBoxWithLister(); boxSize.Margin = new Thickness(12, 0, 12, 12); gridBoxes.Children.Add(boxSize); Grid.SetRow(boxSize, 1); Grid.SetColumn(boxSize, 4); // Create Label to display sample text. lblDisplay = new Label(); lblDisplay.Content = "AaBbCc XxYzZz 012345"; lblDisplay.HorizontalContentAlignment = HorizontalAlignment.Center; lblDisplay.VerticalContentAlignment = VerticalAlignment.Center; gridMain.Children.Add(lblDisplay); Grid.SetRow(lblDisplay, 1); // Create five-column Grid for Buttons. Grid gridButtons = new Grid(); gridMain.Children.Add(gridButtons); Grid.SetRow(gridButtons, 2); for (int i = 0; i < 5; i++) { gridButtons.ColumnDefinitions.Add(new ColumnDefinition()); } // OK button. Button btn = new Button(); btn.Content = "OK"; btn.IsDefault = true; btn.HorizontalAlignment = HorizontalAlignment.Center; btn.MinWidth = 60; btn.Margin = new Thickness(12); btn.Click += OkOnClick; gridButtons.Children.Add(btn); Grid.SetColumn(btn, 1); // Cancel button. btn = new Button(); btn.Content = "Cancel"; btn.IsCancel = true; btn.HorizontalAlignment = HorizontalAlignment.Center; btn.MinWidth = 60; btn.Margin = new Thickness(12); gridButtons.Children.Add(btn); Grid.SetColumn(btn, 3); // Initialize FontFamily box with system font families. foreach (FontFamily fam in Fonts.SystemFontFamilies) { boxFamily.Add(fam); } // Initialize FontSize box. double[] ptsizes = new double[] { 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72 }; foreach (double ptsize in ptsizes) { boxSize.Add(ptsize); } // Set event handlers. boxFamily.SelectionChanged += FamilyOnSelectionChanged; boxStyle.SelectionChanged += StyleOnSelectionChanged; boxWeight.SelectionChanged += StyleOnSelectionChanged; boxStretch.SelectionChanged += StyleOnSelectionChanged; boxSize.TextChanged += SizeOnTextChanged; // Initialize selected values based on Window properties. // (These will probably be overridden when properties are set.) Typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch); FaceSize = FontSize; // Set keyboard focus. boxFamily.Focus(); // Allow updates to the sample text. isUpdateSuppressed = false; UpdateSample(); }