用DocumentViewer控件显示XPS文件 能不能去掉那些多功能按钮 50
2个回答
展开全部
真败了,什么时候提的问题了,现在还没有答的..我来结贴吧,资源文件中添加下面这段代码
<Style x:Key="{x:Type DocumentViewer}" TargetType="{x:Type DocumentViewer}"> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" /> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" /> <Setter Property="FocusVisualStyle" Value="{x:Null}" /> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type DocumentViewer}"> <Border BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Focusable="False"> <Grid KeyboardNavigation.TabNavigation="Local"> <Grid.Background> <SolidColorBrush Color="{DynamicResource ControlLightColor}" /> </Grid.Background> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions>
<ScrollViewer Grid.Row="1" CanContentScroll="true" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled" x:Name="PART_ContentHost" IsTabStop="true" Padding="0" BorderThickness="0"> <ScrollViewer.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="{DynamicResource ControlLightColor}" Offset="0" /> <GradientStop Color="{DynamicResource ControlMediumColor}" Offset="1" /> </LinearGradientBrush> </ScrollViewer.Background> </ScrollViewer> </Grid> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style>
<Style x:Key="{x:Type DocumentViewer}" TargetType="{x:Type DocumentViewer}"> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" /> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" /> <Setter Property="FocusVisualStyle" Value="{x:Null}" /> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type DocumentViewer}"> <Border BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Focusable="False"> <Grid KeyboardNavigation.TabNavigation="Local"> <Grid.Background> <SolidColorBrush Color="{DynamicResource ControlLightColor}" /> </Grid.Background> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions>
<ScrollViewer Grid.Row="1" CanContentScroll="true" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled" x:Name="PART_ContentHost" IsTabStop="true" Padding="0" BorderThickness="0"> <ScrollViewer.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="{DynamicResource ControlLightColor}" Offset="0" /> <GradientStop Color="{DynamicResource ControlMediumColor}" Offset="1" /> </LinearGradientBrush> </ScrollViewer.Background> </ScrollViewer> </Grid> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style>
展开全部
public class DefaultDocumentViewer : DocumentViewer
{
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
var content = ((VisualTreeHelper.GetChild(this, 0) as Border).Child as Grid);
var cc = (content.Children[0] as ContentControl);
if (cc != null)//工具栏
cc.Visibility = System.Windows.Visibility.Collapsed;
var searchBar = content.FindName("PART_FindToolBarHost") as ContentControl;
if (searchBar != null)//搜索栏
searchBar.Visibility = System.Windows.Visibility.Collapsed;
}
}
继承documentViewer,通过视觉树来获取和操作相关控件,代码简单易懂。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询