public class Thumbnail : INotifyPropertyChanged
{
public BitmapImage testimage { get; set; }
Thumbnail()
{
testimage = new BitmapImage(new Uri("http://www.diseno-art.com/news_content/wp-content/uploads/2012/09/2013-Jaguar-F-Type-1.jpg"));
}
}以及自定义控件中的图像元素:
<Image x:Name="previewImage" x:FieldModifier="public" Margin="8" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Source="{Binding Path=thumbnail.testimage}" Stretch="Fill" />当我创建一个控件时,我会这样做:
MyControl MC = new MyControl();
MC.DataContext = new Thumbnail();和图像没有出现-为什么?
发布于 2013-11-22 14:16:40
XAML:
<Image x:Name="previewImage" x:FieldModifier="public" Margin="8" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Source="{Binding Path=testimage}" Stretch="Fill" />代码(清洁剂):
public class Thumbnail : INotifyPropertyChanged
{
private BitmapImage tmpbmp;
public BitmapImage testimage { get { return tmpbmp; } set { tmpbmp = value; OnPropertyChanged("testimage"); } }
public Thumbnail()
{
tmpbmp = new BitmapImage(new Uri("http://www.diseno-art.com/news_content/wp-content/uploads/2012/09/2013-Jaguar-F-Type-1.jpg"));
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}
}发布于 2013-11-22 14:06:24
缩略图类没有公共构造函数,不实现INotifyPropertyChanged成员(在您的示例中根本不需要)。而XAML应是:
<Image x:Name="previewImage" x:FieldModifier="public" Margin="8" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Source="{Binding Path=testimage}" Stretch="Fill" />https://stackoverflow.com/questions/20146657
复制相似问题