简体   繁体   中英

Windows Phone 8 Font Binding

I'm really stumped on how to go about binding fonts to a textbox. I'd like for my user to be able to choose between 3-4 different fonts. I have something like this right now:

<TextBox x:Name="MyTextBox" AcceptsReturn="True"  FontSize="20"
                     FontFamily="{Binding FontSelection}" />

But I have no clue how the c# should look, and I had no luck googling for it. What is the best way to do this? Do I have to create an observable collection? I've tried adding fonts to the Application.Resources, but it wouldn't let me.

Thanks for any answers!

This FontSelection property has to be single item. You could first try simple valid string (like 'Arial'), it could work. Another approach is FontFamily type as poined out by Romasz.

Also there are Converters available, quite easy to implement. http://channel9.msdn.com/Series/Windows-Phone-8-1-Development-for-Absolute-Beginners/Part-25-Advanced-Binding-with-Value-Converters With this you could save user font selection as simple number for example and convert it to appropriate type with Converter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM