private void FontFamilyTextBoxTextChanged(object sender, TextChangedEventArgs e)
 {
     if (String.IsNullOrEmpty(FontFamilyTextBox.Text))
     {
         return;
     }
     foreach (object o in FontFamilyListBox.Items)
     {
         ListBoxItem li = o as ListBoxItem;
         if ((li.Content as String).StartsWith(FontFamilyTextBox.Text, StringComparison.CurrentCultureIgnoreCase))
         {
             if (FontFamilyListBox.SelectedItem != li)
             {
                 FontFamilyListBox.SelectedItem = li;
                 FontFamilyListBox.ScrollIntoView(li);
             }
             break;
         }
     }
 }
        public FontDialog(Protocol.FontOptions currentFont)
        {
            InitializeComponent();

            var families = Fonts.SystemFontFamilies.OrderBy((family) =>
            {
                return(family.Source);
            });

            foreach (var family in families)
            {
                var item = new ListBoxItem()
                {
                    Content = family.Source,
                    VerticalContentAlignment = VerticalAlignment.Top,
                    FontFamily = family,
                    Padding    = new Thickness(2),
                    FontSize   = 14,
                };
                FontFamilyListBox.Items.Add(item);
                if (family.Source == currentFont.Family)
                {
                    FontFamilyListBox.SelectedItem = item;
                }
            }
            FontFamilyListBox.ScrollIntoView(FontFamilyListBox.SelectedItem);

            var colorMap = new Dictionary <string, Color>();

            colorMap.Add("Black", Colors.Black);
            colorMap.Add("Gray", Colors.Gray);
            colorMap.Add("Pink", Colors.Pink);
            colorMap.Add("Red", Colors.Red);
            colorMap.Add("Dark Red", Colors.DarkRed);
            colorMap.Add("Light Blue", Colors.LightBlue);
            colorMap.Add("Blue", Colors.Blue);
            colorMap.Add("Teal", Colors.Teal);
            colorMap.Add("Dark Blue", Colors.DarkBlue);
            colorMap.Add("Light Green", Colors.LightGreen);
            colorMap.Add("Green", Colors.Green);
            colorMap.Add("Dark Green", Colors.DarkGreen);

            foreach (var pair in colorMap)
            {
                var brush = new SolidColorBrush(pair.Value);
                brush.Freeze();

                ColorComboBox.Items.Add(new ComboBoxItem()
                {
                    Content    = pair.Key,
                    Foreground = brush,
                });
            }
            ColorComboBox.SelectedIndex = 0;

            int[] sizes = { 6, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 36, 40 };

            foreach (int size in sizes)
            {
                SizeComboBox.Items.Add(new ComboBoxItem()
                {
                    Content = size.ToString()
                });
            }
            SizeComboBox.SelectedIndex = 5;

            if (currentFont.Style.HasFlag(Protocol.FontStyle.Bold))
            {
                BoldCheckBox.IsChecked = true;
            }
            if (currentFont.Style.HasFlag(Protocol.FontStyle.Italic))
            {
                ItalicCheckBox.IsChecked = true;
            }
            if (currentFont.Style.HasFlag(Protocol.FontStyle.Underline))
            {
                UnderlineCheckBox.IsChecked = true;
            }
        }