views:

53

answers:

1

I am creating a UserControl in Silverlight 4 which has a watermarked background.

The watermark should change depending on the underlying 'type' the UserControl is representing.

The watermark is created using a Path and I have extracted all the properties into a style.

I was wondering if it would be possible to change the style of the Path at runtime based on some known value.

I am using MVVM and Unity. Perhaps I could bind the style somehow? Or could I inject the style when the view is created?

I may have to do this with control templates, hence the reference in the title.

Thanks...

A: 

Instead of using control templates to change the style of the watermark, why dont you use the VisualStateManager to change the state of the watermark based on the 'type'.

dParker
My original idea was to have all the watermarks present and combine a DataTrigger, bound to the Type property of the DataContext, with a series of ChangePropertyActions to switch the visibility of the various watermarks as according to type.Unfortunately this didn't seem to work. Probably because the model containing the type is passed into the constructor of the ViewModel so OnPropertyChanged is never fired for Type and thus the DataTrigger is also not fired.
elggarc
My second idea was to bind the Visibility property of the watermark to the Type property and use a converter, passing in an appropriate parameter to identify which watermark the Visibility property was on, to check if the Type matched the parameter and then return an appropriate visibility.I see no reason why this shouldn't work, but my boss wasn't keen.
elggarc
I eventually pursuaded my boss to go with the converter option.
elggarc