【问题标题】:Image source in Class Library类库中的图像源
【发布时间】:2013-03-22 19:47:14
【问题描述】:

我正在尝试为我的 WinRT 应用程序创建一个用户控件,为此我在我的解决方案中创建了一个类库。 类库有一个名为“Images”的文件夹,其中有一个 icon.png。在 Generic.xaml 文件中,在控件模板中我有这个:

<Style TargetType="local:MyControl">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="local:MyControl">
                <Button Background="Transparent">
                    <StackPanel HorizontalAlignment="Center">
                        <Image Source="/Images/icon.png" Width="64" Height="64"/>
                    </StackPanel>
                </Button>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

当我在应用程序中使用此控件时,没有显示图像。我不知道问题是什么。我曾尝试使用 ms-appx 和 ../,但没有任何效果。图像构建选项设置为内容。

【问题讨论】:

    标签: xaml windows-8 windows-runtime


    【解决方案1】:

    您需要改用以下格式:

    Source="ms-appx:///MyLibrary/Images/icon.png" />
    

    将 MyLibrary 替换为您的 dll 的名称。

    【讨论】:

    • 这对我不起作用,现在它在 MyLibrary/MyLibrary/Images/icon.png 目录中搜索
    • 这在我运行我的应用程序时效果很好,但是 Visual Studio 或 Resharper 说找不到该文件,所以我认为它无论如何都行不通,谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-22
    • 1970-01-01
    • 1970-01-01
    • 2011-07-23
    • 1970-01-01
    • 1970-01-01
    • 2019-04-22
    相关资源
    最近更新 更多