1

Closed

Move the shapes in ShapeFactory into Xaml

description

Instead of defining the shapes in code, i'd define them as application resources in App.xaml.
Closed Jun 12, 2008 at 11:50 PM by
Cool!

comments

shockstump wrote Jun 11, 2008 at 11:30 PM

like this:







You can then load the shapes in your ShapeFactory:

Shape s= Application.Current.Resources["square"] as Shape ;

The benefit of this is that your 'designer' is able to make your shapes look pretty in Blend whilst you concentrate on the code

shanselman wrote Jun 12, 2008 at 6:33 AM

Good idea! I tried this but thought I got an error when I added more than one. I'll try again.

shanselman wrote Jun 12, 2008 at 6:39 AM

So, I tried that just now and have a problem. When I add the shape that is in a resource, TWICE, the first one displayed disappears, because, of course, it's the SAME shape. How do I get a shape out of a resource and REUSE it?

shockstump wrote Jun 12, 2008 at 8:59 AM

good point! ok, so rather than storing the actual shapes in the resource dictionary, store their styles:











Then ShapeFactory can apply the styles:

Shape shape = new Rectangle();
shape.Style = Application.Current.Resources["square"] as Style;

This approach still has the advantage of letting your designer make your shapes look nice for you using Blend.

shanselman wrote Jun 12, 2008 at 8:03 PM

Cool. I'll try this. How does this make things better in Blend? The Style markup looks like something I'll need to make by hand?

shockstump wrote Jun 12, 2008 at 10:27 PM

You can use Blend 2.5 June Preview to create Style resources in the WYSIWYG IDE, so you don't need to code these by hand :-)