Fredrik Hedblad Fredrik Hedblad - 1 year ago 162
C# Question

BasedOn="{StaticResource {x:Type TextBox}}" in Code Behind for Style

How can you set the following in code behind?

<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">

I'm using a Theme merged in App.xaml. It works great for all Controls but when I define a Style for something, e.g.
, the Theme Style doesn't get picked up unless I use
like above, instead it gets the default

Now I'm creating a
in code behind and I can't get the
part to work for the

Style editingStyle = new Style(typeof(TextBox));
editingStyle.BasedOn = ...?;

Any suggestions? Also, is there any way to get the Theme Style instead of the default Style applied without using BasedOn?


Answer Source

Try this:

editingStyle.BasedOn = (Style) FindResource(typeof (TextBox))

And I don't know any way how you can make it apply the Theme style without specifying BasedOn. If there is such a way, I would like to know it too...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download