微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

silverlight – 在XAML中绑定图像源

我试图通过c#将图像源绑定到我的XAML

这很有效

<Image Source="images/man.jpg"></Image>

这不起作用

<Image Source="images/{Binding imagesource}"></Image>

其中imagesource是此xaml的c#文件中的字符串变量,并且设置为“man.jpg”

解决方法

这是在XAML中如何做到这一点的方法

将其添加到命名空间:

xmlns:System="clr-namespace:System;assembly=mscorlib"

然后添加您的图像路径

<System:String x:Key="ImageRefresh">/Theme;component/Images/icon_refresh.png</System:String>
<System:String x:Key="ImageSearch">/Theme;component/Images/icon_search.png</System:String>

这就是你如何使用它

<Image Height="16" Source="{StaticResource ImageSearch}" Stretch="Uniform" Width="16"/>

这样可以正常工作,但是如果你在Blend中加载你的xaml风格,它会变得虚伪..

“System.String”类型的对象不能应用于需要“System.Windows.Media.ImageSource”类型的属性.

我还没想到,如何用Media.ImageSource替换System:String …但是嘿..它在Visual Studio中适用于我.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐