tags:

views:

747

answers:

1

I have created a default style for my textbox controls, but I would like to be able to change the style at runtime.

I have a property that I want to bind to that informs the UI if the data is mandatory or not, and I want to be able to change the style of the textbox to another style that displays a red line under the textbox. I can't use this in the standard textbox style I've created because the property is different for each textbox i.e. IsEmailMandatory, isNameMandatory.

I've tried to bind a data trigger in the style of the textbox for each textbox I have, but I get a message telling me I can't change a style within a style. so how do I do this?

A: 

You don't need to change the whole style in the trigger, just the template.

Another way to achieve something similar would be to use attached properties. Assuming that the IsEmailMandatory, isNameMandatory properties are on the DataContext not the control itself, you could then bind the value you want to an attached property and then trigger off that in your default style.

Greg Bacchus