我有以下课程:
public class Sticky : INotifyPropertyChanged {
// ... some members
private BitmapImage _frontPic;
[DataMember]
public BitmapImage FrontPic {
get {
return _frontPic;
}
set {
_frontPic = value;
Changed("FrontPic");
Changed("FrontBrush");
}
}
}
我正在尝试将其数据绑定到此 XAML:
<Image Width="173" Height="173" Source="{Binding FrontPic}" />
在我的 PhoneApplicationPage 中使用此代码启动 PhotoChooserTask 后:
public Sticky Sticky { get; set; }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) {
Sticky = new Sticky();
DataContext = Sticky;
}
private void ShowFrontPicPicker(object sender, RoutedEventArgs e) {
var t = new PhotoChooserTask();
t.PixelHeight = 173;
t.PixelWidth = 173;
t.ShowCamera = true;
t.Completed += (s, ev) => {
if (ev.TaskResult == TaskResult.OK) {
var img = new BitmapImage();
img.SetSource(ev.ChosenPhoto);
Sticky.FrontPic = img;
}
};
t.Show();
}
但是,我的图像仍然是空白的。如果我将 Image.Source 属性直接分配给 Image 而不进行数据绑定,则一切正常。数据绑定其他属性有效,只是图像似乎是问题所在。如何使图像上的 DataBinding 工作?