Exemple #1
0
        private void OnSelectedFontFamilyChanged()
        {
            if (_fontFamilyListBox == null)
            {
                return;
            }

            _isInternalUpdate = true;

            // Select matching entry in list box.
            IEnumerable <FontFamilyDescription> fontFamilyItems = (IEnumerable <FontFamilyDescription>)_fontFamilyListBox.ItemsSource;
            var selectedItem = fontFamilyItems.FirstOrDefault(item => item.FontFamily.Equals(SelectedFontFamily));

            _fontFamilyListBox.SelectedItem = selectedItem;

            // Get display name.
            var displayName = (selectedItem != null) ? selectedItem.DisplayName : string.Empty;

            // Scroll list box entry into view.
            if (selectedItem != null)
            {
                _fontFamilyListBox.ScrollIntoView(selectedItem);
            }

            // If text box does not already contain a matching text, update the text box.
            // Do nothing if the cursor is currently in the text box (the user is typing).
            if (!_fontFamilyTextBox.IsKeyboardFocused && string.Compare(_fontFamilyTextBox.Text, displayName, true, CultureInfo.CurrentCulture) != 0)
            {
                _fontFamilyTextBox.Text = displayName;
            }

            // ----- Initialize typefaces list.
            // Fill the font family list box.
            if (SelectedFontFamily == null)
            {
                _typefaceListBox.ItemsSource = null;
            }
            else
            {
                var typefaces = SelectedFontFamily.GetTypefaces();

                // Create a text block for each font family
                var items = new List <TypefaceDescription>(typefaces.Count);
                foreach (var typeface in typefaces)
                {
                    var item = new TypefaceDescription
                    {
                        DisplayName  = FontHelper.GetDisplayName(typeface.FaceNames),
                        FontFamily   = SelectedFontFamily,
                        IsSymbolFont = FontHelper.IsSymbolFont(SelectedFontFamily),
                        Typeface     = typeface,
                    };

                    items.Add(item);
                }

                // Sort items by display name and assign the to the list box.
                items.Sort((a, b) => FontHelper.Compare(a.Typeface, b.Typeface));
                _typefaceListBox.ItemsSource = items;

                // Update the typeface controls.
                OnSelectedTypefaceChanged();
            }

            _isInternalUpdate = false;
        }
Exemple #2
0
        private void OnSelectedFontFamilyChanged()
        {
            if (_fontFamilyListBox == null)
                return;

            _isInternalUpdate = true;

            // Select matching entry in list box.
            IEnumerable<FontFamilyDescription> fontFamilyItems = (IEnumerable<FontFamilyDescription>)_fontFamilyListBox.ItemsSource;
            var selectedItem = fontFamilyItems.FirstOrDefault(item => item.FontFamily.Equals(SelectedFontFamily));
            _fontFamilyListBox.SelectedItem = selectedItem;

            // Get display name.
            var displayName = (selectedItem != null) ? selectedItem.DisplayName : string.Empty;

            // Scroll list box entry into view.
            if (selectedItem != null)
                _fontFamilyListBox.ScrollIntoView(selectedItem);

            // If text box does not already contain a matching text, update the text box.
            // Do nothing if the cursor is currently in the text box (the user is typing).
            if (!_fontFamilyTextBox.IsKeyboardFocused && string.Compare(_fontFamilyTextBox.Text, displayName, true, CultureInfo.CurrentCulture) != 0)
                _fontFamilyTextBox.Text = displayName;

            // ----- Initialize typefaces list.
            // Fill the font family list box.
            if (SelectedFontFamily == null)
            {
                _typefaceListBox.ItemsSource = null;
            }
            else
            {
                var typefaces = SelectedFontFamily.GetTypefaces();

                // Create a text block for each font family
                var items = new List<TypefaceDescription>(typefaces.Count);
                foreach (var typeface in typefaces)
                {
                    var item = new TypefaceDescription
                    {
                        DisplayName = FontHelper.GetDisplayName(typeface.FaceNames),
                        FontFamily = SelectedFontFamily,
                        IsSymbolFont = FontHelper.IsSymbolFont(SelectedFontFamily),
                        Typeface = typeface,
                    };

                    items.Add(item);
                }

                // Sort items by display name and assign the to the list box.
                items.Sort((a, b) => FontHelper.Compare(a.Typeface, b.Typeface));
                _typefaceListBox.ItemsSource = items;

                // Update the typeface controls.
                OnSelectedTypefaceChanged();
            }

            _isInternalUpdate = false;
        }