简体   繁体   中英

DocumentViewer remove the ToolBar drop shadow

I have read lots of topics for removing toolbar or search bar in a DocumentViewer Control but i can't remove the drop shadow effect of the toolbar..

Do you have an idea ?

I have looped into children of the control but it's does not work.

在此处输入图片说明

Here is the visual tree (the selected Rectangle is the drop shadow your refer to):

在此处输入图片说明

The following code hides the Rectangle:

class MyDocumentViewer : DocumentViewer
{
    public void RemoveToolbarShadow()
    {
        var r = this.FindType<System.Windows.Controls.Border>()?
            .FindType<Grid>()?
            .FindType<DockPanel>()?
            .FindType<System.Windows.Shapes.Rectangle>();

        if (null != r) r.Visibility = Visibility.Hidden;
    }
}

Helper extension:

static class DependencyObjectExtensions
{
    internal static T FindType<T>(this DependencyObject reference) where T : DependencyObject
    {
        int n = VisualTreeHelper.GetChildrenCount(reference);
        for (int i = 0; i < n; i++)
        {
            var c = VisualTreeHelper.GetChild(reference, i) as T;
            if (null != c) return c;
        }
        return null;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM