尝试访问资源时出现 XamlParseException [英] XamlParseException when trying to access Resource

查看:26
本文介绍了尝试访问资源时出现 XamlParseException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用默认图标之一作为 Xaml 代码中按钮的内容.我真的不明白出了什么问题,因为图像在 UI 伪模拟器中显示时可以正常加载,但是当我尝试部署它时,如果我进入视图,则会抛出 System.Windows.Markup.XamlParseException.

I'm trying to use one of the default icons as the content of a button in my Xaml code. I don't really understand what's going wrong because the image loads fine when shown in the UI pseudo-emulator but when I try to deploy it I get a System.Windows.Markup.XamlParseException thrown if I enter the view.

这是涉及的代码:

<phone:PhoneApplicationPage.Resources>
    <Image x:Key="IButton"  Source="/Assets/AppBar/cancel.png"/>
</phone:PhoneApplicationPage.Resources>

 <Button x:Name="AmaemiaButton" Content="{StaticResource IButton}" HorizontalAlignment="Right"   Margin="375,-45,0,0" Grid.Row="1" VerticalAlignment="Top" Width="65" Height="65" FontSize="22" Click="AmaemiaButton_Click" Opacity="100" />

第一个片段位于 xaml 标记的顶部,按钮调用位于 Grid &列表视图.

The first snippet is at the top of the xaml markup, and the button call is inside a Grid & Listview.

我已将问题追溯到Content="{StaticResource IButton}"",但找不到资源调用的问题.

I've traced the problem to the 'Content="{StaticResource IButton}"' But can't find the problem with the calling of the resource.

任何帮助将不胜感激!

推荐答案

您可以执行以下操作:

<phone:PhoneApplicationPage.Resources>

    <ImageSource x:Key="IButton">/Assets/AppBar/cancel.png</ImageSource>

</phone:PhoneApplicationPage.Resources>

<phone:PhoneApplicationPage.Resources>

    <BitmapImage x:Key="IButton"
                 UriSource="/Assets/ApplicationBar.Cancel.png" />

</phone:PhoneApplicationPage.Resources>

<小时>

<Button x:Name="AmaemiaButton"
                    HorizontalAlignment="Right"
                    Margin="375,-45,0,0"
                    Grid.Row="1"
                    VerticalAlignment="Top"
                    Width="65"
                    Height="65"
                    FontSize="22"
                    Click="AmaemiaButton_Click"
                    Opacity="1.0">
                <Button.Content>
                        <Image Source="{StaticResource IButton}" />
                </Button.Content>
            </Button>

这篇关于尝试访问资源时出现 XamlParseException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆