Fixing an Image/Drawing so it doesn't auto-size
-
I'm having this weird minor problem that I can't seem to figure out, probably because I don't understand enough of why it's happening. I have an ImageDrawing that I draw some shapes in, and then animate those shapes. Due to the animation, the size of the drawing changes, as do its edges relative to the "center" of the drawing, if you will, (or any fixed point in the drawing). What's happening is WPF is treating the image as an encapsulated object whose dimensions keep changing, resulting in it constantly "re-centering" itself, which results in my drawing moving around on the window when I want it to be completely fixed (so that the individual shapes animate, but the drawing as a whole stays in the same spot). Basically as far as I can tell is happening is the drawing is being "trimmed" (like in Photoshop), rather than staying a fixed size like a canvas. Any idea how to stop this happening? I've tried a few things like giving the Image a fixed width and height, but the drawing inside it still does the same trimming thing. Also I can't set HorizontalAlignment or VerticalAlignment because the top/bottom and left/right edges of the drawing still change (thanks again to the trimming).
“Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’) Built with home-grown CodeProject components! -”-”-
-
I'm having this weird minor problem that I can't seem to figure out, probably because I don't understand enough of why it's happening. I have an ImageDrawing that I draw some shapes in, and then animate those shapes. Due to the animation, the size of the drawing changes, as do its edges relative to the "center" of the drawing, if you will, (or any fixed point in the drawing). What's happening is WPF is treating the image as an encapsulated object whose dimensions keep changing, resulting in it constantly "re-centering" itself, which results in my drawing moving around on the window when I want it to be completely fixed (so that the individual shapes animate, but the drawing as a whole stays in the same spot). Basically as far as I can tell is happening is the drawing is being "trimmed" (like in Photoshop), rather than staying a fixed size like a canvas. Any idea how to stop this happening? I've tried a few things like giving the Image a fixed width and height, but the drawing inside it still does the same trimming thing. Also I can't set HorizontalAlignment or VerticalAlignment because the top/bottom and left/right edges of the drawing still change (thanks again to the trimming).
“Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’) Built with home-grown CodeProject components! -”-”-
I suppose I could put some invisible rectangle large enough to cover the area, but there must be a better way...
“Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’) Built with home-grown CodeProject components! -”-”-
-
I suppose I could put some invisible rectangle large enough to cover the area, but there must be a better way...
“Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’) Built with home-grown CodeProject components! -”-”-
Well I changed things around to use Line objects on a Canvas instead of LineGeometry's in an ImageDrawing and now I'm not having that problem. Not sure if I will incur a performance penalty doing it this way, but it seems a lot easier, and besides, it will allow me to do other things I was wanting to do (such as change opacity of individual pieces of the drawing) that I didn't realize weren't possible doing it the other way, so I think I'll stick with this. One more question for anyone who happens to be paying attention: It seems rather cumbersome to have to declare the stroke color, stroke thickness, start cap and end cap for every single Line object I create. It would be much handier if I could group these under some logical parent, and attach those properties once to the parent, and have them inherited by each child Line. In fact, I thought this was the whole point of attached properties, yet when I try to attach Shape.StrokeThickness (for example) to Canvas, I get an error that it can't find the attachable property. Is there some other way to achieve the same thing?
“Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’) Built with home-grown CodeProject components! -”-”-
-
Well I changed things around to use Line objects on a Canvas instead of LineGeometry's in an ImageDrawing and now I'm not having that problem. Not sure if I will incur a performance penalty doing it this way, but it seems a lot easier, and besides, it will allow me to do other things I was wanting to do (such as change opacity of individual pieces of the drawing) that I didn't realize weren't possible doing it the other way, so I think I'll stick with this. One more question for anyone who happens to be paying attention: It seems rather cumbersome to have to declare the stroke color, stroke thickness, start cap and end cap for every single Line object I create. It would be much handier if I could group these under some logical parent, and attach those properties once to the parent, and have them inherited by each child Line. In fact, I thought this was the whole point of attached properties, yet when I try to attach Shape.StrokeThickness (for example) to Canvas, I get an error that it can't find the attachable property. Is there some other way to achieve the same thing?
“Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’) Built with home-grown CodeProject components! -”-”-
Oh wait, duh, I know the answer to that: styles! :doh:
“Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’) Built with home-grown CodeProject components! -”-”-