我有這個當前工作爲一個數據綁定WPF圖像:WPF圖像UriSource,數據綁定和緩存
<Image Source="{Binding ThumbFile}" />
簡單。
現在,添加緩存到這個圖像(我想能夠操作/刪除本地文件後,已被加載)。我發現你可以添加一個CacheOption =「OnLoad」給標籤中的標籤。
<Image>
<Image.Source>
<BitmapImage UriSource="{Binding Path=ThumbFile, Converter={StaticResource myConverter2}}" />
</Image.Source>
</Image>
然後,我不得不有一個轉換器將本地文件轉換爲BitmapImage。
<local:LocalUriToImageConverter x:Key="myConverter2"/>
和
public class LocalUriToImageConverter : System.Windows.Data.IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null)
{
return null;
}
if (value is string)
{
value = new Uri((string)value);
}
if (value is Uri)
{
System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage();
bi.BeginInit();
//bi.DecodePixelWidth = 80;
bi.DecodePixelHeight = 60;
bi.UriSource = (Uri)value;
bi.EndInit();
return bi;
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new Exception("The method or operation is not implemented.");
}
}
出於某種原因,這還沒有開始工作。沒有錯誤,但控制似乎不受約束。即使控件創建了許多實例,ThumbFile屬性和Converter中的斷點也沒有達到。切換回其他圖像源標籤工作正常。
什麼都沒有?失敗的綁定等...? –
什麼也沒有。我經歷了很多不同的錯誤,試圖達到它的效果,但最終在實際工作中終止了錯誤。 – elbweb