How do I write a datatrigger to change the value of a dependency property based on a change of a second dependency property?

If the dependency properties in question are defined on the UserControl you need to set it's style property, not add a default style inside the resources.

If the dependency properties in question are defined on the UserControl you need to set it's style property, not add a default style inside the resources. To set the style inline in XAML.

Thanks for the response Adam. I was under the impression that any Style with a target type and no name would automatically be assigned to all targets that match, so I don't see why your method would be any different. However I tried it anyway, but still get the same result (the setter is never called).

Any more ideas? I added a sentence of clarification to the original post about the DPs ("In case its relevant, the "ViewType" bound property is defined in a parent UserControl, and the "Mode" property is defined on MyUserControl. ") – Locksleyu Oct 18 at 17:18 1 it would be helpful if you provided the control heirachy.

You are correct about a default style (no key only, targettype) however it will be applied to all children of the UserControl it is defined in. If this usercontrol is the same as the one you are trying to effect in the triggers it won't be used (as it is not a child of itself) – Adam Mills Oct 18 at 17:31 Also check for binding errors in the output window. – Adam Mills Oct 18 at 17:32 I checked the output window, no binding errors there.

Since it still doesn't work even when defining the style specifically as you mention, I don't think the control hierarchy is related the problem, though the usercontrol is the same one where I am trying to effect the triggers. – Locksleyu Oct 18 at 19:39 @Locksleyu What Adam says is correct. The style is not being applied because it's scope is "all children inside the UserControl", and that doesn't include the UserControl itself.

S syntax would make the style apply to the UserControl itself, if the Mode property is not explicitly set on the UserControl. See msdn.microsoft. Com/en-us/library/ms743230.

Aspx for more details. I have also occasionally encountered an issue where I need to set a default setter in the style in order for triggered setters to work, so you could give that a try. – Rachel Oct 18 at 19:55.

If you do, it is overwriting the triggered value. Also, on occasion I have had issues with a triggered value not getting set unless a default value is also defined in the style. For example, sometimes this will not work while this does.

Thanks for the ideas Rachel. I don't have any places in the UserControl's XAML where I am setting the Mode property, but there are several places in the code behind where I am setting it (based on other events such as button presses, etc. ). I hope this isn't a problem because the value of Mode is based on several different conditions.

Probably a slightly better name for it would be 'state' as it reflects the state of the control at any point in time. – Locksleyu Oct 19 at 13:44 @Locksleyu If you define a property explicitly on the object, either in XAML or Code-Behind, it will overwrite any styled or triggered values. One alternative is to set the value in the Style, such as with a binding, because then the Triggered value is allowed to overwrite it.

See the following link for more information about of the order in which DependencyProperties are applied: msdn.microsoft. Com/en-us/library/ms743230. Aspx – Rachel Oct 19 at 14:10 Rachel, by "define a property explicitly on the object" are you referring to setting the value (i.e.

Mode=NextState; in code), or are you referring to creating the dependency property itself? I am creating a custom dependency property in the code via DependencyProperty.Register(), does this mean that I can't safely set that DP via a datatrigger/setter? – Locksleyu Oct 19 at 15:24 @Locksleyu Sorry for the confusion, I mean setting the value in code such as Mode=NextState – Rachel Oct 19 at 15:28 Ok, thanks for clarifying.

I made an answer post with an update (it ended up above this one for some reason), check it out if you get a chance. – Locksleyu Oct 197 at 11:47.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions