// Update font family list based on selection. // Return list item if there's an exact match, or null if not. private FontFamilyListItem SelectFontFamilyListItem(FontFamily family) { FontFamilyListItem listItem = fontFamilyList.SelectedItem as FontFamilyListItem; if (listItem != null && listItem.FontFamily.Equals(family)) { // Already selected return(listItem); } else if (SelectListItem(fontFamilyList, FontFamilyListItem.GetDisplayName(family))) { // Exact match found return(fontFamilyList.SelectedItem as FontFamilyListItem); } else { // Not in the list return(null); } }
// Handle changes to the SelectedFontFamily property private void OnSelectedFontFamilyChanged(FontFamily family) { // If the family list is not valid do nothing for now. // We'll be called again after the list is initialized. if (_familyListValid) { // Select the family in the list; this will return null if the family is not in the list. FontFamilyListItem item = SelectFontFamilyListItem(family); // Set the text box to the family name, if it isn't already. string displayName = (item != null) ? item.ToString() : FontFamilyListItem.GetDisplayName(family); if (string.Compare(fontFamilyTextBox.Text, displayName, true, CultureInfo.CurrentCulture) != 0) { fontFamilyTextBox.Text = displayName; } // The typeface list is no longer valid; update it in the background to improve responsiveness. InvalidateTypefaceList(); } }