Tech Off Post

Single Post Permalink

View Thread: Saving a rendered bitmap from a WPF visual in MVVM.
  • User profile image

    I've got an application that needs to write a sort of "screenshot" of a control to disk as a bitmap. I can use RenderTargetBitmap.Render() to render the visual and everything, but how do I do this from the viewmodel?

    The viewmodel receives a message (via the MVVMLight Messenger classes) that a bitmap needs to be saved, and in order to do that, it needs a reference to the visual. Which means a reference to the view, which ties my viewmodel to my specific view, which I don't want.

    Another idea would be to have the view render the bitmap and expose it to the view in some way via a OneWayToSource binding, but I have no idea how to tell it when to update via the viewmodel.

    Anyone got any ideas?