Modifying DockPane top title style (font/colours) and colour of the top line

166
2
01-27-2021 05:59 PM
FredericPoliart_EsriAU
New Contributor II

Is there a way to modify the DockPane caption colour?
(That is the text that appears in the dockPane tab and on top of the pane)

Also is there a way to change the colour of the thin horizontal bar on top of a dock Pane?

dockpane_font_colour_hz_bar.png

 

Is there perhaps a  <dockPane style? > to add in the config.daml ?

0 Kudos
2 Replies
KirkKuykendall1
Occasional Contributor III
0 Kudos
KirkKuykendall1
Occasional Contributor III

It might be easier to use VS Live Visual Tree to find what elements Esri uses in their controls, then use Microsoft's VisualTreeHelper to find those elements and change their properties.

Before:

KirkKuykendall1_0-1612210498319.png

After:

KirkKuykendall1_1-1612210551749.png

The live visual tree is kinda quirky, but this works:

KirkKuykendall1_2-1612210668032.png

Eventually Visual Studio should show what you picked:

KirkKuykendall1_3-1612210723015.png

 

Now use VisualTreeHelper to find the elements. From the code behind:

 

 

private void Button_Click(object sender, RoutedEventArgs e)
{
    try
    {
        // use VS "live visual tree" to determine what to change
        var newBrush = new SolidColorBrush(Colors.Green);
        var toolwindow = GetAncestor("ToolWindowContainer");
        var list = GetFlattenedList(toolwindow);
        var border = list.OfType<Border>()
                    .Where(b => b.Name == "esri_colorBar").FirstOrDefault();
        if (border == null)
            throw new Exception("esri_colorBar not found");
        border.Background = newBrush;
        var title = list.OfType<TextBlock>()
                    .Where(tb => tb.Name == "title").FirstOrDefault();
        if (title == null)
            throw new Exception("title textblock not found");
        title.Foreground = newBrush;
    }
    catch (Exception ex)
    {
        Debug.Print(ex.Message);
    }
}
private DependencyObject GetAncestor(string prefix)
{
    var depObj = VisualTreeHelper.GetParent(this);
    FrameworkElement elem = this;
    while (depObj != null && !depObj.ToString().StartsWith(prefix))
    {
        //Debug.Print($"{depObj}");
        depObj = VisualTreeHelper.GetParent(depObj);
    }
    if (depObj == null)
        throw new Exception($"{prefix} not found");
    return depObj;
}
private List<DependencyObject> GetFlattenedList(DependencyObject o)
{
    var outList = new List<DependencyObject>();
    var stack = new Stack<DependencyObject>();
    stack.Push(o);
    while(stack.Count > 0)
    {
        o = stack.Pop();
        for(int i = 0;i< VisualTreeHelper.GetChildrenCount(o);i++)
        {
            var child = VisualTreeHelper.GetChild(o, i);
            stack.Push(child);
            outList.Add(child);
        }
    }
    return outList;
}

Of course if Esri changes something in a future release this might break.

 

 

0 Kudos