Gus*_*nti 5 data-binding wpf image
假设我在我的DataContext中将字符串Name和Image Photo作为类的属性.我需要将它们绑定到控件是一个DataTemplate.
我认为这会起作用,但它没有:
<Image Source="{Binding Photo}"/>
Run Code Online (Sandbox Code Playgroud)
为什么不?我的照片应该是另一种吗?(也许是BitmapImage?)
如何将Image控件绑定到Image属性?
谢谢!
编辑:像往常一样,点击提交后我看到错误很明显:没有从Image到ImageSource的转换器.我的转换器如何将Image转换为ImageSource?
拥有 Image 类型的数据属性实际上没有意义,因为 Image 是一个控件(如果您确实想要这样做,可以绑定到 Photo.Source)。您应该使用 ImageSource (或 BitmapImage,就像您所做的那样,因为 BitmapImage 继承自 ImageSource)。
| 归档时间: |
|
| 查看次数: |
11699 次 |
| 最近记录: |