Cache ContentControl/ContentPresenter Bound to ViewModel
If I have a ContentControl/ContentPresenter whose content will be set to a ViewModel - and I have a type-referential data template for the ViewModel - is there a clean, MVVM-compliant way to take a "snapshot" of the ContentControl/Content开发者_如何学编程Presenter when it has rendered everything?
The idea is that I will have up to three or four ViewModels "open" at any given point in time, and I will have a ListBox bound to a collection of the ViewModels. There will be one ContentControl/ContentPresenter displaying the "current" view model being viewed. If the user moves their mouse over one of the ViewModels in the ListBox, I want to display a scaled down preview of the ViewModel for them. Rather than rendering the content everytime, I want to cache the content for a ViewModel once it has been displayed initially in the main ContentPresenter.
Has anyone seen anything like this before?
Chris
You can create a bitmap of any visual using RenderTargetBitmap. The bitmap will include the entire visual tree of the visual.
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.rendertargetbitmap.aspx
http://msdn.microsoft.com/en-us/library/aa969775.aspx
精彩评论