none
有关DocumentViewer控件的样式问题? RRS feed

答案

  • 很简单,你可以不用理会它本身的样式怎么设置的,你就自己写自己的样式,然后把他们指定到 ContentControl Style 属性上。你甚至还可以指定 ContentTemplate, 不过这样可能会覆盖它本身已实现的功能。


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • 已标记为答案 xxyxxb2080 2011年10月10日 1:09
    2011年10月9日 15:14
    版主

全部回复

  • 上图的style如下:

    xmlns:System_Windows_Documents="clr-namespace:System.Windows.Documents;assembly=PresentationUI"

    <Style BasedOn="{x:Null}" TargetType="{x:Type DocumentViewer}">
       <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
       <Setter Property="Background" Value="Red"/>
       <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
       <Setter Property="ContextMenu" Value="{DynamicResource {ComponentResourceKey ResourceId=PUIDocumentViewerContextMenu, TypeInTargetAssembly={x:Type System_Windows_Documents:PresentationUIStyleResources}}}"/>
       <Setter Property="Template">
        <Setter.Value>
         <ControlTemplate TargetType="{x:Type DocumentViewer}">
          <Border BorderBrush="{TemplateBinding BorderBrush}"
             BorderThickness="{TemplateBinding BorderThickness}" Focusable="False">
           <Grid Background="Red" KeyboardNavigation.TabNavigation="Local">
            <Grid.ColumnDefinitions>
             <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
             <RowDefinition Height="Auto"/>
             <RowDefinition Height="*"/>
             <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <ContentControl Grid.Column="0" Focusable="{TemplateBinding Focusable}" Grid.Row="0"
            Style="{DynamicResource {ComponentResourceKey ResourceId=PUIDocumentViewerToolBarStyleKey, TypeInTargetAssembly={x:Type System_Windows_Documents:PresentationUIStyleResources}}}"
            TabIndex="0"/>工具栏
            <ScrollViewer x:Name="PART_ContentHost" CanContentScroll="true" Grid.Column="0" Focusable="{TemplateBinding Focusable}" HorizontalScrollBarVisibility="Auto" IsTabStop="true" Grid.Row="1" TabIndex="1"/>
            <DockPanel Grid.Row="1">
             <FrameworkElement DockPanel.Dock="Right"
             Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"/>
             <Rectangle Height="10" Visibility="Visible" VerticalAlignment="top">
              <Rectangle.Fill>
               <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                <LinearGradientBrush.GradientStops>
                 <GradientStopCollection>
                  <GradientStop Color="#66000000" Offset="0"/>
                  <GradientStop Color="Transparent" Offset="1"/>
                 </GradientStopCollection>
                </LinearGradientBrush.GradientStops>
               </LinearGradientBrush>
              </Rectangle.Fill>
             </Rectangle>
            </DockPanel>
            <ContentControl x:Name="PART_FindToolBarHost"
            Grid.Column="0" Focusable="{TemplateBinding Focusable}" Grid.Row="2" TabIndex="2"/>//搜索栏
           </Grid>
          </Border>
         </ControlTemplate>
        </Setter.Value>
       </Setter>
      </Style>

    2011年10月8日 6:27
  • 很简单,你可以不用理会它本身的样式怎么设置的,你就自己写自己的样式,然后把他们指定到 ContentControl Style 属性上。你甚至还可以指定 ContentTemplate, 不过这样可能会覆盖它本身已实现的功能。


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • 已标记为答案 xxyxxb2080 2011年10月10日 1:09
    2011年10月9日 15:14
    版主