简体   繁体   English

Windows Phone 8字体绑定

[英]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. 我希望我的用户能够在3-4种不同的字体之间进行选择。 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. 但是我不知道C#的外观,也没有运气。 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. 我尝试将字体添加到Application.Resources中,但它不允许我这样做。

Thanks for any answers! 感谢您的任何答案!

This FontSelection property has to be single item. 此FontSelection属性必须是单个项目。 You could first try simple valid string (like 'Arial'), it could work. 您可以先尝试使用简单的有效字符串(例如“ Arial”),然后再运行。 Another approach is FontFamily type as poined out by Romasz. 另一种方法是Romasz提出的FontFamily类型。

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. http://channel9.msdn.com/Series/Windows-Phone-8-1-Development-for-Absolute-Beginners/Part-25-Advanced-Binding-with-Value-Converters这样您就可以将用户字体选择另存为例如简单数字,然后使用Converter将其转换为适当的类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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