I have a WPF control with a GeometryModel3D
with DiffuseMaterial
using an ImageBrush
with data bound ImageSource
.
My goal is to display a "cross-section" while hovering the mouse, and for that I can already get the proper position on the object. The problem is: There is no "3D Line" in WPF.
I have made a test drawing the line in the image I use for ImageSource
and the visual result is exactely what I want.
So I plan to do the following: generate the base image once, and then draw the appropriate line on it, setting the property used as ImageSource
.
I have considered two approaches:
Have the bound ImageSource of type
BitmapImage
. Then I create aSystem.Drawing.Bitmap
once with the blank texture (without the line), and then each time I want the line to change position, I recreate theBitmapImage
drawing a line withSystem.Drawing.Graphics
;Have the bound ImageSource of type
DrawingGroup
. Then I create aSystem.Windows.Media.ImageDrawing
once, and then each time I want the line to change position, I recreate theDrawingGroup
by changing only theGeometryDrawing
composed by one single line.
Is there any inherent advantage of one method over the other?
I ended up replacing the old GDI+ based "Graphics over Bitmap and then convert to BitmapImage" by a very WPF/XAML friendly way of generating the image with a somewhat bulky but actually very straightforward way of stacking "layers" of
Drawing
objects, with elimination of A LOT of code-behind.The line itself is a hard-coded one, with its
Geometry.Transform.Y
property being directly set by events in code-behind using thealturaFatia
Name.