2016-05-13 20 views
1

我想實現一個自定義的BitmapSource類,該類提供偶爾更改的圖像。 BitmapSource如何向其消費者發出圖像已更改且必須重新加載的信號?具有動態內容的自定義BitmapSource

例如,調用AddDirtyRect後的WritableBitmap更新的使用者。我想在我的BitmapSource類中創建一個類似的機制。

一個等同的問題是:ImageSource的用戶如何知道圖像已更改並應重新加載?

+1

您可以使用JetBrains dotPeek來查看PresentationCore程序集中的WriteableBitmap源代碼。 – Clemens

+0

您是否檢查過類[DrawableImage](https://msdn.microsoft.com/de-de/library/system.windows.media.drawingimage%28v=vs.110%29.aspx)? – JanDotNet

回答

0

編寫自定義的BitmapSource的一些信息和示例代碼有我用來做這一種解決方法。 。

  1. 創建ImageProvider類,從DependencyObjectINotifyPropertyChanged繼承與只讀ImageSource您在填寫財產

  2. 將這個供應商的情況下在你Window/Control資源是這樣的:

<Window> <Window.Resources> <controls:MyImageProvider x:Key="Provider" /> </Window.REsources> </Window>

  • 綁定你的形象在ImageSource財產上的供應商:
  • <Image Source="{Binding ImageSource, Source={StaticResource Provider}" />

    要刷新的圖像
  • 每次,在您的提供商上設置ImageSource屬性,並讓WPF處理更新。
  • 相關問題