silverlight - 在 XAML 中绑定(bind)图像源

标签 silverlight xaml image

我正在尝试通过 c# 将图像源绑定(bind)到我的 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 中对我有用。

关于silverlight - 在 XAML 中绑定(bind)图像源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3366166/

相关文章:

javascript - 在 Silverlight 中接收来自 HtmlPage 主机的回调

silverlight - 带有本地数据库的浏览器 silverlight 4 应用程序可以在 Windows 或 Mac 上运行和安装吗?

wpf - ContextMenu.PlacementTarget 未设置,不知道为什么

c# - 如何使 TextBlock 在 GridViewColumn 中居中? (包括示例 xaml)

java - j2me中如何显示在线图片?

c# - WPF中的嵌套ObservableCollection数据绑定(bind)

flash - Silverlight P2P 应用程序(在浏览器中)- 我们会得到 RTMFP 吗?

c# - WPF DataGrid 通过绑定(bind)设置样式

html - 如何使用 HTML+CSS+JS 将图像上的响应式图像设置为固定显示?

java - 有没有更快的方法来处理 java android 中的数组?