答案 0 :(得分:1)
这是可视化树(所选矩形是您引用的投影):
以下代码隐藏了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;
}
}
助手扩展:
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;
}
}