Silverlight - 将 ImageSource 绑定到矩形填充
Blend 4 告诉我这是无效的标记,但没有告诉我原因:
<ImageBrush Stretch="Fill" ImageSource="{Binding Avatar, Mode=OneWay}"/>
我从 Twitter 提要中提取数据,保存到 ImageSource,然后将其绑定到 ImageBrush(如下所示)以用作填充一个矩形。以下是更多上下文:
<Rectangle x:Name="Avatar" RadiusY="9" RadiusX="9" Width="45" Height="45" VerticalAlignment="Center" HorizontalAlignment="Center" >
<Rectangle.Fill>
<ImageBrush Stretch="Fill" ImageSource="{Binding Avatar, Mode=OneWay}"/>
</Rectangle.Fill>
</Rectangle>
我在 Silverlight UserControl 内部使用它,该控件在 Silverlight 应用程序内部使用。关于问题可能是什么的任何想法吗?
Blend 4 is telling me this is invalid markup and its not telling me why:
<ImageBrush Stretch="Fill" ImageSource="{Binding Avatar, Mode=OneWay}"/>
I'm pulling data from a Twitter feed, saving to an ImageSource, and then binding it to an ImageBrush(as seen below) to be used as the Fill for a Rectangle. Here is more context:
<Rectangle x:Name="Avatar" RadiusY="9" RadiusX="9" Width="45" Height="45" VerticalAlignment="Center" HorizontalAlignment="Center" >
<Rectangle.Fill>
<ImageBrush Stretch="Fill" ImageSource="{Binding Avatar, Mode=OneWay}"/>
</Rectangle.Fill>
</Rectangle>
I'm using this inside of a Silverlight UserControl, which is used inside of a Silverlight Application. Any Ideas on what the problem could be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
绑定不能应用于 ImageBrush 的 ImageSource,或者看起来是这样。我遇到了类似的问题并正在寻找替代方案。
Binding cannot be applied to an ImageBrush's ImageSource, or so it seems. I'm having a similar issue and looking for alternatives.
您无法绑定到 ImageBrush 的 ImageSource,但可以绑定到 Shape 的 Fill 属性。所以下面的工作是这样的:
使用像这样的类:
和像这样的隐藏代码:
You can't bind to the ImageSource of an ImageBrush, however you can bind to the Fill property of a Shape. So the following works:
With a class something like this:
and code behind like this:
给你:WPF / Silverlight
Here you go : WPF / Silverlight