如何在WPF DocumentViewer控件工具栏中折叠CopyButton?

如何在WPF DocumentViewer控件工具栏中折叠CopyButton?,wpf,documentviewer,Wpf,Documentviewer,我想折叠WPF Documentviewer控件工具栏中的“复制”按钮。 我在样式中添加了一个触发器,将可见性设置为“折叠”。但它不起作用。你知道为什么吗 <DocumentViewer Grid.Row="1" Margin="0,0,40,0" Name="documentViewer" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" > <DocumentViewer.Resou

我想折叠WPF Documentviewer控件工具栏中的“复制”按钮。 我在样式中添加了一个触发器,将可见性设置为“折叠”。但它不起作用。你知道为什么吗

 <DocumentViewer Grid.Row="1" Margin="0,0,40,0" Name="documentViewer" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
            <DocumentViewer.Resources>
                <Style TargetType="ContentControl">
                    <Style.Triggers>
                        <Trigger Property="Name" Value="PART_FindToolBarHost">
                            <Setter Property="Visibility" Value="Collapsed" />
                        </Trigger>
                        <Trigger Property="Name" Value="CopyButton">
                            <Setter Property="Visibility" Value="Collapsed" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DocumentViewer.Resources>
        </DocumentViewer>

据我所知,如果不更改整个控件的样式,则无法折叠复制按钮。。。 因此,这里有一个适合您的样式(警告大量代码输入)

(来源=):


结果:

当然,您必须修改它以满足您的需要

如果您不想使用基于样式的解决方案,请查看以下链接:

您可以使用查找
CopyButton
并在加载
DocumentViewer
后将其隐藏

private void DocumentViewer_Loaded(object sender, RoutedEventArgs e)
{
    var button = UIHelper.FindChild<Button>(documentViewer, "CopyButton");
    button.Visibility = Visibility.Collapsed;
}
private void DocumentViewer\u已加载(对象发送方,路由目标)
{
var-button=UIHelper.FindChild(documentViewer,“CopyButton”);
button.Visibility=Visibility.Collapsed;
}

嗨,丹尼斯,谢谢你的回答。我知道要修改控制模板。但我们失去了默认工具栏上的图标。所以我很担心它,因为图标的显示看起来不错。我们可以在您的解决方案的每个按钮内容中添加图标,但我们没有类似的图标,我是UX专家,可以进行完全类似的设计。我理解并同意您的观点!下面一个人似乎知道更多的检查hius答案!此外,对于所有类型的图标需要,我通常使用这个网站的私人免费和商业价值的钱,如果你问我,我很惊讶为什么触发器没有工作。现在我采用代码隐藏的方法,通过visualtree找到CopyButtin并将其折叠。谢谢你,米佳。
private void DocumentViewer_Loaded(object sender, RoutedEventArgs e)
{
    var button = UIHelper.FindChild<Button>(documentViewer, "CopyButton");
    button.Visibility = Visibility.Collapsed;
}