[英]Data binding image to Panorama Control in WP7 not working
谁能阐明为什么以下代码不起作用? “不起作用”是指图像未在Panorama控件中呈现:
XAML
DataContext="{Binding RelativeSource={RelativeSource Self}}"
shell:SystemTray.IsVisible="False">
<Grid x:Name="LayoutRoot">
<controls:Panorama Title="My Control">
<controls:Panorama.Background>
<ImageBrush ImageSource="{Binding RandomImage}"/>
</controls:Panorama.Background>
C#
public string RandomImage { get; set; }
注意: RandomImage属性设置为Internet上的公共jpg图像。
编辑
我也尝试过将RandomImage属性更改为ImageSource,但是没有任何运气。
我要RandomImage
猜想,您是在页面加载后的某个时候设置RandomImage
,这意味着绑定已被检查。 您需要实现INotifyPropertyChanged
并在Setter中为RandomImage
调用PropertyChanged
事件。 有关此内容的详细说明,请查看此MSDN文章 。
它的长处和短处是在页面加载时检查绑定,然后除非有什么触发它,否则不会再次检查。 实现INotifyPropertyChanged
意味着,当您调用PropertyChanged
事件时,它将通知UI再次检查绑定并查看新内容,以便它可以自我更新。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.