views:

275

answers:

2

I would like to create a button control that has a Path element as its content--an IconButton if you will.

This button should fulfill two conditions:

1. The Path element's stroke and fill colors should be available for manipulation by the VisualStateManager.

2. The Path element's data string (which defines it's shape) can be set in code or in XAML, so that I can create several such buttons without creating a new custom control for each.

The only way I can see to do it would involve no XAML whatsoever. That is, setting all the visual states and animations in the code behind, plus generating the Geometry objects point by point (and not being able to use the convenient Data string property on the Path element).

Is there a simpler way to do this?

EDIT

So one of the limitations I'm running into is that Silverlight does not support the mini-language for path expressions in PathGeometry, only in Path. I've got some detailed geometry going on in some of these icons, and I really don't want to take the convenient strings I generated with an Illustrator plug-in (pretty sure it was this one) and make them into separate line segments and curves.

A: 

The Path Data property is simply a Geometry. When you say "several such buttons" one assumes that there are a finite number of such buttons which vary with Icon.

Store each "Icon" as a PathGeomerty in a ResourceDictionaryand have that ResourceDictionary referenced as a merged dictionary in the app.xaml.

Now you can simply assign the geomerty into the Path shap Data property.

AnthonyWJones
The main problem I was trying to solve was to be able to 1) set the path geometry dynamically, while 2) allowing the path stroke and fill colors to be manipulated by the VisualStateManager.
Klay
A: 

For the second part of the problem above, here's a kludge which works pretty well for storing string Path data as resources and accessing them from code.

For the first part of the problem, I just created all the animations in code, apply them on mouse events, got rid of the XAML page altogether.

Klay

related questions