Disable Style in WPF XAML?

For setting the style to default,

In XAMl use,

<TextBox Style="{x:Null}" />

In C# use,

myTextBox.Style = null;

If style needs to be set as null for multiple resources, see CodeNaked’s response.


I feel, all the additional info should be in your question and not in the comments. Anyways, In code Behind I think this is what you are trying to achieve:

Style myStyle = (Style)Application.Current.Resources["myStyleName"];

public void SetDefaultStyle()
{
    if(Application.Current.Resources.Contains(typeof(TextBox)))
        Application.Current.Resources.Remove(typeof(TextBox));

    Application.Current.Resources.Add(typeof(TextBox),      
                                      new Style() { TargetType = typeof(TextBox) });
}

public void SetCustomStyle()
{
    if (Application.Current.Resources.Contains(typeof(TextBox)))
        Application.Current.Resources.Remove(typeof(TextBox));

    Application.Current.Resources.Add(typeof(TextBox), 
                                      myStyle);
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)