How to plug a custom font into your application in Windows Phone 8.1 development

Source: Internet
Author: User
Tags file url


Perhaps, the system comes with the font is not enough to reflect the charm of the application, for the performance of extremely strong Chinese characters, especially. At this time, we will think, if you can download the art of the Internet into the application package, it is not beautiful? So, can this be achieved? The answer is yes.



Next, Allah will show you how to embed a custom font in WP 8.1 two development frameworks respectively.



Why are two big frames? We know that the development framework from 7x to 8.0 is Silverlight for Windows Phone, in order to facilitate compatibility and direct project upgrades, in 8.1, Microsoft's development team still retains this framework; Another framework is the set of APIs ported from win RT application, I do not need to say more, guess also guessed, is convenient to write and Windows flat-panel applications for general applications prepared.



Of course, if only the development of WP application, then two frames can be used, you see which is pleasing to use which, does not matter, much the same; if you plan to write a generic program, you can only choose the runtime API set, that is, a subset that is ported from RT applications.



But I tell you, no matter which frame, there is no essential difference, at least it is the same, Microsoft later many development technology is from WPF, save a good continuity, you just learn WPF, the other framework can not learn from the pass.



In a word, remember my words: technology and knowledge is always dead, people are always alive, do not learn to die of knowledge .



Run-time APIs



First look at how to embed a custom font under the runtime API. This is a lot simpler.



1. Open omnipotent vs, create a new project, project template Select "Blank application (Windows Phone)", all the templates in parentheses that indicate "windows Phone" are based on the Run-time APIs from RT porting. As pictured.






2, open the Solution Explorer window (don't ask me where), with the right mouse button desperately click on the project name node, from the pop-up menu select "Add"-"Existing Items", select a font file, fonts can be online, many are.



3. Open the MainPage.xaml page, declare a TextBlock element, and then select the TextBlock in the XAML editor, then open the Properties window, find the FontFamily attribute, and click the Drop-down list, and you will see the font file that you just added to the project.






Notice that a symbol is added to the right of the custom font that you add to the item. This will generate the following XAML:


<textblock fontfamily= "Yu Wei calligraphy Script simplified ... ttf#yuweij".


Even URLs do not have to write their own, from which we see the reference font file method is "file URL + # + font name." #Behind is the name of the font. 4, fix, now put some text into the TextBlock.


<textblock fontfamily= "Yu Wei calligraphy script simplified. Ttf#yuweij" fontsize= ">"
            Deng Yellow Crane Tower "<linebreak/> Cuihao
                    < LineBreak/>
            Xiren has taken yellow crane to go, <linebreak/>
            here spare yellow Crane Tower. <linebreak/>
            Yellow crane is gone, <linebreak/>
            white clouds thousand empty leisurely. <linebreak/>
            Clear Sichuan hanyang tree, <linebreak/>
            Grass Parrot state. <linebreak/>
            Where is the sunset, <linebreak/>
            Enpa River on the people worry.
        </TextBlock>


Now, you can run it. Look at the application page, is not found that temperament immediately promoted nine grades?



See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.