wpf 引用ttf viewmodel绑定

预览字体

引用字体

<UserControl.Resources> 
<!-- 方式一 -->
        <FontFamily x:Key="IconFont">
            Pack://application:,,,/MyApp;component/font/#fontname
        </FontFamily>
<!-- 方式二 -->
        <FontFamily x:Key="iconFontTest">/Test.Server;Component/src/#iconfont</FontFamily>
    </UserControl.Resources>

viewmodel

使用

如果在viewmodel中或后台代码中使用,直接使用xe692即可(移除开头的&#,换成\,然后将结尾的;移除)

也可以通过System.Net.WebUtility.HtmlDecode("")解码就可以在viewmodel中使用

前台直接绑定

txt.Text = "\xe621";

控件绑定字体

 FontFamily="{StaticResource IconFont}"
posted @ 2021-05-27 17:08  Hey,Coder!  阅读(124)  评论(0)    收藏  举报