Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight 在合并字典中找不到字体_Silverlight - Fatal编程技术网

Silverlight 在合并字典中找不到字体

Silverlight 在合并字典中找不到字体,silverlight,Silverlight,我正在使用Silverlight 3的外部库中的合并词典,并且我在资源文件(styles.xaml)中定义的样式已正确应用于我的按钮控件 我想给我的按钮应用一种字体,并且我的字体与我的styles.xaml位于同一目录中(在外部dll中,以build action作为资源)。在styles.xaml中,我有: <Style x:Key="MyButtonStyle" TargetType="Button"> <Setter Property="Back

我正在使用Silverlight 3的外部库中的合并词典,并且我在资源文件(styles.xaml)中定义的样式已正确应用于我的按钮控件

我想给我的按钮应用一种字体,并且我的字体与我的styles.xaml位于同一目录中(在外部dll中,以build action作为资源)。在styles.xaml中,我有:

<Style  x:Key="MyButtonStyle"
        TargetType="Button">
    <Setter Property="Background"
            Value="#FF1F3B53" />
    <Setter Property="Foreground"
            Value="#FF000000" />
    <Setter Property="Padding"
            Value="3" />
    <Setter Property="BorderThickness"
            Value="1" />
     <Setter Property="FontFamily"
            Value="VINERTIC.TTF#Viner Hand ITC" />

等等

但是,不应用该字体。我尝试将字体文件放在App.XAML目录中,但仍然没有应用。 如果我将字体应用于样式之外,则效果很好

JD

编辑
忽略此回复,仅当所有内容都在同一程序集中时,此回复才有效。


我刚试过这个,它对我有效。我就是这样做的:

字体文件(ttf)位于应用程序的根目录下。生成操作为“资源”,并且选择了“不复制”

我有一个“资源”文件夹,也在应用程序的根目录下。在这里,我有Assets1.xaml和Assets2.xaml。两者的生成操作都是“资源”,并且选择了“不复制”。在Assets1.xaml中,我有一些无关紧要的东西。在Assets2.xaml中,我列出了以下内容:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Style x:Key="DeveloperStyle"
           TargetType="TextBox">

        <Setter Property="FontFamily"
                Value="ProggyTiny.ttf#ProggyTinyTT"></Setter>

        <Setter Property="FontSize"
                Value="16"></Setter>

    </Style>

</ResourceDictionary>

在App.xaml中,我做到了这一点(请注意,我为我的应用程序使用了基类,但这不应该有什么区别):


当我将样式应用于同一项目中的文本框时,它将使用自定义字体显示

编辑
忽略此回复,仅当所有内容都在同一程序集中时,此回复才有效。


我刚试过这个,它对我有效。我就是这样做的:

字体文件(ttf)位于应用程序的根目录下。生成操作为“资源”,并且选择了“不复制”

我有一个“资源”文件夹,也在应用程序的根目录下。在这里,我有Assets1.xaml和Assets2.xaml。两者的生成操作都是“资源”,并且选择了“不复制”。在Assets1.xaml中,我有一些无关紧要的东西。在Assets2.xaml中,我列出了以下内容:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Style x:Key="DeveloperStyle"
           TargetType="TextBox">

        <Setter Property="FontFamily"
                Value="ProggyTiny.ttf#ProggyTinyTT"></Setter>

        <Setter Property="FontSize"
                Value="16"></Setter>

    </Style>

</ResourceDictionary>

在App.xaml中,我做到了这一点(请注意,我为我的应用程序使用了基类,但这不应该有什么区别):



当我将样式应用于同一项目中的文本框时,它将使用自定义字体显示

好的,我想我现在拿到了。事实证明,您需要引用字体文件及其所在程序集的路径。假设您有一个名为MyResourceAssembly的单独程序集和一个名为Resources的文件夹。此文件夹中有Assets1.xaml、Assets2.xaml和您的字体文件。对于这三种情况,构建操作都设置为“资源”。在应用程序(我们称之为MyApp)中,有App.xaml,可以在其中合并两个资源文件

Assets2.xaml的内容:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Style x:Key="DeveloperStyle"
           TargetType="TextBox">

        <Setter Property="FontFamily"
                Value="/MyResourceAssembly;component/Resources/ProggyTiny.ttf#ProggyTinyTT"></Setter>

        <Setter Property="FontSize"
                Value="16"></Setter>

    </Style>

</ResourceDictionary>

下面是在App.xaml中合并资源字典的方法:

<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      x:Class="MyApp">
    <Application.Resources>

        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/MyResourceAssembly;component/Resources/Assets1.xaml" />
                <ResourceDictionary Source="/MyResourceAssembly;component/Resources/Assets2.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>

    </Application.Resources>
</Application>

好的,我想我现在拿到了。事实证明,您需要引用字体文件及其所在程序集的路径。假设您有一个名为MyResourceAssembly的单独程序集和一个名为Resources的文件夹。此文件夹中有Assets1.xaml、Assets2.xaml和您的字体文件。对于这三种情况,构建操作都设置为“资源”。在应用程序(我们称之为MyApp)中,有App.xaml,可以在其中合并两个资源文件

Assets2.xaml的内容:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Style x:Key="DeveloperStyle"
           TargetType="TextBox">

        <Setter Property="FontFamily"
                Value="/MyResourceAssembly;component/Resources/ProggyTiny.ttf#ProggyTinyTT"></Setter>

        <Setter Property="FontSize"
                Value="16"></Setter>

    </Style>

</ResourceDictionary>

下面是在App.xaml中合并资源字典的方法:

<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      x:Class="MyApp">
    <Application.Resources>

        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/MyResourceAssembly;component/Resources/Assets1.xaml" />
                <ResourceDictionary Source="/MyResourceAssembly;component/Resources/Assets2.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>

    </Application.Resources>
</Application>


很抱歉我的答复过早。当您在单独的程序集中处理东西时,它显然更复杂。但我想我已经解决了,我只需要再努力一点。我会回来的…很抱歉我过早的回复。当您在单独的程序集中处理东西时,它显然更复杂。但我想我已经解决了,我只需要再努力一点。“我会回来的……”亨里克。谢谢你的详细答复。今天晚些时候我会试一试,如果一切顺利,我会告诉你。@Henrik。谢谢你的详细答复。今天晚些时候我会试一试,如果一切正常,我会告诉你。