Displaying FontFamily in Combobox

后端 未结 3 1808
闹比i
闹比i 2021-02-15 17:04

My goal is to manipulate the text-styles of my application via DependencyProperties. I got a diagram in which the texts are to be manipulated in size, fontfamily, color, etc. So

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-15 17:46

    ItemsSource here expects a collection; e.g. Fonts.SystemFontFamilies

    
    

    Actually, here's a very nice link covering font selection:

    http://www.hanselman.com/blog/LearningWPFWithBabySmashCustomerFeedbackAndAWPFFontComboBox.aspx

    Scott Hanselman even shows how to render each font item in combobox with it's own font family.


    Added per OP comment.

    Here's an example of binding to dependency property. Property is named "MyFontFamily" to avoid collision with existing Window's property. Sorry, no Ribbon controls (I have bare 3.5 sp1).

    Window1.xaml

    
        
            
            
        
    
    

    Window1.xaml.cs

    public partial class Window1 : Window
    {
        // ...
    
        public static readonly DependencyProperty MyFontFamilyProperty =
            DependencyProperty.Register("MyFontFamily",
            typeof(FontFamily), typeof(Window1), new UIPropertyMetadata(null));
    }
    

提交回复
热议问题