Visualizer for WPF Elements

Attempt to create a visualization for some WPF elements, including DrawingImageand UIElementetc. While creating a visualizer was trivial, my visualizers always be ruled out that the types of targets ( DrawingImageand UIElement) are not marked as serializable .

Further reading showed what I need to implement VisualizerObjectSourceto provide custom serialization. This class is indicated as one of the arguments in the attribute DebuggerVisualizer. I followed the steps below and now my name is a custom serializer, but I don’t know what to do with it. Here is the corresponding function called:

public override void GetData(object target, Stream outgoingData)
{
  var writer = new StreamWriter(outgoingData);
  writer.WriteLine(/*???*/);
  writer.Flush();
}

I don’t understand what exactly expects from me (binary-serialized version UIElement?), And how exactly do I write UIElementor DrawingImageto the outgoing stream. Has anyone done this before?

+4
source share
1 answer

I finally managed to get through this. This is a lot easier than I thought. For others who are trying to find their way, here's how it works:

First, the GetData()override (read question) should be managed by YOU. You need to decide what you want to send to the visualizer. Send enough information so you can restore an object in a call Show().

WPF , , . XamlReader XamlWriter, / WPF.

Show(), Form. , Visual Studio Form Control ( WinForms), WPF Window s, , ElementHost , WPF ElementHost.

ViewBox ElementHost , .

WPFVisualizers GitHub , - . DrawingImage UIElement. WPF, , . VisualizerBase, / . WPF , 1 , :

public class GeometryDrawingVisualizer : VisualizerBase<GeometryDrawing, GeometryDrawingControl>
{
}

. GeometryDrawing. (GeometryDrawingControl ) - WinForms Control ( Form, ), . ElementHost , , .

+2

Source: https://habr.com/ru/post/1653706/


All Articles