I have created a custom control that serves as the basis for a few others I'm making. I've then defined control templates for each one, so now I can do the following:
<!-- First layout -->
<custom:MyCustomControl Style="{StaticResource CustomStyle1}" />
<!-- Second layout -->
<custom:MyCustomControl Style="{StaticResource CustomStyle2}" />
...
etc.
I then wanted to make it so I could switch from one style to another with the press of a button. My initial idea to do this was to create custom Button
with a StyleToApply
dependency property and a way to find its containing parent. I would then set the button's OnClick
method to change the style of its containing control's to that of the button's dependency property. However, my styles don't get recognised:
<!-- Within a custom control or user control -->
<local:StyleButton StyleToApply="{StaticResource ResourceKey}" ... />
^ no suggested styles
Is it even possible to achieve this? If so, how? If not, what could I do instead?