WPF Style Inheritance Behavior

Recently I was using a window style with MahAppsMetro, now it applies the styles at application level. One of the things I am doing is embedding AvalonEdit in one such window. Now with Metro styling it applies styles to the controls and in my case SearchPanel in AvalonEdit was styled too! This is fine, but the results were quite un-expected:

Metro Styling applied to SearchPanel

Metro Styling applied to SearchPanel

Now, of course I do want to keep Metro Style for my application, however want to keep AvalonEdit styling intact as well.

Thinking further the simplest thing to do would be to be to somehow disable inheritance of styles at some level. I found a post on stackoverflow discussing this. However for me it was not to stop inheriting styles but to fallback to theme. Documentation on this topic is pretty scarce.

Now to get things to work, I wrapped the AvalonEdit.TextEditor in a custom Control which would InheritanceBehavior.SkipToThemeNow.

and xaml was modified to use this NoInheritanceContentControl

    <local:NoInheritanceContentControl Grid.Column="2" >
            <ed:TextEditor Name="_txtEd" IsReadOnly="True" ShowLineNumbers="True" 
                           FontFamily="Consolas" 
                           FontSize="10pt"/>
    </local:NoInheritanceContentControl>
        

and the code for the same is:

public class NoInheritanceContentControl : ContentControl
    {
        //  https://stackoverflow.com/a/2138114
        //  but here skip to theme instead of skipping all
        //  otherwise the SearchPanel is rendered completely translucent
        //
        public NoInheritanceContentControl()
        {
            InheritanceBehavior = InheritanceBehavior.SkipToThemeNow;
        }
    }

With following changes, I get the SearchPanel to show up correctly:


InheritanceBehavior


InheritanceBehavior has following members and I was curious how each of them turn out:

    //
    // Summary:
    //     Indicates the current mode of lookup for both property value inheritance, a resource
    //     lookup, and a RelativeSource FindAncestor lookup.
    public enum InheritanceBehavior
    {
        //
        // Summary:
        //     Property value inheritance lookup will query the current element and continue
        //     walking up the element tree to the page root.
        Default = 0,
        //
        // Summary:
        //     Property value inheritance lookup will not query the current element or any further.
        SkipToAppNow = 1,
        //
        // Summary:
        //     Property value inheritance lookup will query the current element but not any
        //     further.
        SkipToAppNext = 2,
        //
        // Summary:
        //     Property value inheritance lookup will not query the current element or any further.
        SkipToThemeNow = 3,
        //
        // Summary:
        //     Property value inheritance lookup will query the current element but not any
        //     further.
        SkipToThemeNext = 4,
        //
        // Summary:
        //     Property value inheritance lookup will not query the current element or any further.
        SkipAllNow = 5,
        //
        // Summary:
        //     Property value inheritance lookup will query the current element but not any
        //     further.
        SkipAllNext = 6
    }


Default



SkipToAppNow



SkipToAppNext



SkipToThemeNow



SkipToThemeNext



SkipAllNow



SkipAllNext