类库中的图像源

时间:2013-03-22 19:47:14

标签: xaml windows-8 windows-runtime

我正在尝试为我的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和../但没有任何效果。图像构建选项设置为内容。

1 个答案:

答案 0 :(得分:2)

您需要使用以下格式:

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

将myLibrary替换为您的dll名称。