我正在尝试将2个新按钮添加到文档查看器控件中,然后我们将其托管在Windows窗体中,因此我从MSDN中取出模板进行修改,但所有内容都是"内置的"标准按钮转到显示屏上的文字而不是图标。我想知道是否有人可以帮助我解释为什么会发生这种情况以及如何解决它,因为我无法从MSDN文档中确定。不过我是XAML的新手。下面是修改后的控件的xaml。
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:Documents="clr-namespace:System.Windows.Documents;assembly=PresentationUI" x:Class="AddinXPSViewer.XPSBrowser"
xmlns:self="clr-namespace:AddinXPSViewer"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
>
<Frame x:Name="DocFrame">
<Frame.Content>
<Grid>
<DocumentViewer x:Name="docViewer" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="0,0,0,0" Unloaded="docViewer_Unloaded" Style="{DynamicResource DocumentViewerStyle}" ContextMenu="{x:Null}" >
<DocumentViewer.Resources>
<Style x:Key="DocumentViewerStyle" TargetType="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="Template">
<Setter.Value>
<ControlTemplate TargetType="DocumentViewer">
<Grid KeyboardNavigation.TabNavigation="Local">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ToolBar
ToolBarTray.IsLocked="True"
KeyboardNavigation.TabNavigation="Continue">
<Button Command="ApplicationCommands.Copy"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
Content="Copy"/>
<Separator />
<Button Command="NavigationCommands.IncreaseZoom"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
Content="Zoom In"/>
<Button Command="NavigationCommands.DecreaseZoom"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
Content="Zoom Out"/>
<Separator />
<Button Command="NavigationCommands.Zoom"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
CommandParameter="100.0"
Content="Actual Size" />
<Button Command="DocumentViewer.FitToWidthCommand"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
Content="Fit to Width" />
<Button Command="DocumentViewer.FitToMaxPagesAcrossCommand"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
CommandParameter="1"
Content="Whole Page"/>
<Button Command="DocumentViewer.FitToMaxPagesAcrossCommand"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
CommandParameter="2"
Content="Two Pages"/>
<Button Command="self:XPSBrowserCustomCommands.Next">Previous</Button>
<Button Command="self:XPSBrowserCustomCommands.Previous">Next</Button>
</ToolBar>
<ScrollViewer Grid.Row="1"
CanContentScroll="true"
HorizontalScrollBarVisibility="Auto"
x:Name="PART_ContentHost"
IsTabStop="true"/>
<ContentControl Grid.Row="2"
x:Name="PART_FindToolBarHost"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DocumentViewer.Resources>
<DocumentViewer.CommandBindings>
<CommandBinding Command="ApplicationCommands.Print" Executed="CommandBinding_OnPrint" />
<CommandBinding Command="ApplicationCommands.Print" CanExecute="CommandBinding_CanExecutePrint" />
<CommandBinding Command="self:XPSBrowserCustomCommands.Next" Executed="CommandBinding_OnPrevious" />
<CommandBinding Command="self:XPSBrowserCustomCommands.Next" CanExecute="CommandBinding_CanExecutePrevious" />
<CommandBinding Command="self:XPSBrowserCustomCommands.Previous" Executed="CommandBinding_OnNext" />
<CommandBinding Command="self:XPSBrowserCustomCommands.Previous" CanExecute="CommandBinding_CanExecuteNext" />
</DocumentViewer.CommandBindings>
</DocumentViewer>
</Grid>
</Frame.Content>
</Frame>
</UserControl>
答案 0 :(得分:1)
秘诀是在visual studio中右键单击并编辑模板或模板的副本两次,这将为msdn上的模板提供一个不同的模板,并访问工具栏的子控件。
答案 1 :(得分:0)
在每个Button
上,Content
属性设置为字符串值。
例如Content="Copy"
如果您希望它成为图片,则必须将其设置为Image
控件。
e.g。
<Button>
<Image Source="copy.png"/>
</Button>
&#39;默认模板&#39;在MSDN上不是WPF的实际默认模板。它们只是用于制作您自己的控件模板的示例代码。