私はカスタムリストビューテンプレートを持っています(以下のようなもの):
<ListView.ItemTemplate>
<DataTemplate >
<albc:MultithreadImage
filename="{Binding Path=thumbnailpath,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Name="theImage"/>
</DataTemplate >
</ListView.ItemTemplate>
ListView のItemsSourceは、 Photoクラスのコレクションにバインドされています。
カスタム コントロール MultithreadImage は画像を適切に表示しますが、Photo クラスでサムネイルパスを変更してNotifyPropertyChanged("thumbnailpath")を起動すると、MultithreadImage で画像が更新されません
Photo クラスはINotifyPropertyChangedを実装しています
誰でも助けることができますか?
以下の MultithreadedImage を確認します。
class MultithreadImage:System.Windows.Controls.Image
{
public string filename
{
get {
return (string)GetValue(filenameProperty); }
set {
SetValue(filenameProperty, value);
}
}
public string temp = "";
BitmapImage source2;
private static void OnFilenameChanged(DependencyObject defectImageControl, DependencyPropertyChangedEventArgs eventArgs)
{
var control = (MultithreadImage)defectImageControl;
control.temp = control.filename;
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += (o, e) =>
{
try
{
//http://stackoverflow.com/questions/6430299/bitmapimage-in-wpf-does-lock-file
var bmi = new BitmapImage();
bmi.BeginInit();
bmi.CacheOption = BitmapCacheOption.OnLoad;
bmi.UriSource = new Uri(control.temp);
bmi.EndInit();
control.source2 = bmi;
control.source2.Freeze();
}
catch
{
}
};
bw.RunWorkerCompleted += (o, e) =>
{
if (control.source2 != null)
control.Source = control.source2;
};
bw.RunWorkerAsync(control);
}
// Using a DependencyProperty as the backing store for filename. This enables animation, styling, binding, etc...
public static readonly DependencyProperty filenameProperty =
DependencyProperty.Register("filename", typeof(string), typeof(MultithreadImage),
new FrameworkPropertyMetadata(
// use an empty Guid as default value
"",
// tell the binding system that this property affects how the control gets rendered
FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
// run this callback when the property changes
OnFilenameChanged
)
);
}