wpf documentViewer预览缩略图?

时间:2018-07-17 12:18:18

标签: wpf thumbnails xps documentviewer

我正在使XPS文档查看器消失。 如何为每个页面创建缩略图并将其作为按钮的图像源?

这是我的XAML:

 <Canvas x:Name="myCanvas" Loaded="myCanvas_Loaded" SizeChanged="myCanvas_SizeChanged" >

            <DocumentViewer x:Name="Viewer" HorizontalAlignment="Center" VerticalAlignment="Center" Canvas.Left="10" Canvas.Top="10" Width="780" Height="430" HorizontalPageSpacing="20">
                <DocumentViewer.Resources>

                    <!-- Hides the search box-->
                    <Style TargetType="ContentControl">
                        <Setter Property="Visibility" Value="Collapsed" />
                    </Style>

                    <!-- Hides the toolbar -->
                    <Style TargetType="ToolBar">
                        <Setter Property="Visibility" Value="Collapsed" />
                    </Style>
                </DocumentViewer.Resources>
                <i:Interaction.Behaviors>
                    <Behaviours:MultitouchTransformBehavior x:Name="multitouchTransformBehavior" Duration="0:0:0.6" AllowRotate="False" MaximumScale="30" />
                </i:Interaction.Behaviors>
            </DocumentViewer>
    <StackPanel x:Name="test" Height="80" Width="65" MouseEnter="test_MouseEnter" MouseLeave="test_MouseLeave" Background="Transparent">
        <Image x:Name="Image1" Tag="1" Height="56" Source="/ShopfloorAppXpsViewer;component/Penguins.jpg" Margin="0,15,0,0" MouseDown="Image_MouseDown"/>
        <Image x:Name="Image2" Tag="2" Height="54" Source="/ShopfloorAppXpsViewer;component/Penguins.jpg" Margin="0,15,0,0" MouseDown="Image_MouseDown"/>
    </StackPanel>

</Canvas>

图像源现已修复!在按钮上,单击我将切换到所选页面。

后面的代码:

 private void myCanvas_Loaded(object sender, RoutedEventArgs e)
{
  try
  {
    string xpsFilePath = System.IO.Path.GetFullPath("XPS/" + RunViewModel._textToDisplay + ".xps");
    XpsDocument myDoc = new XpsDocument(xpsFilePath, FileAccess.Read);
    Viewer.Document = myDoc.GetFixedDocumentSequence();
    Viewer.FitToHeight();
    Viewer.FitToWidth();
   test.Height = ActualHeight;
    //  test.Height = ActualHeight;
    //Viewer.Height = 600;
    //Viewer.Width = 800;
  }
  catch (Exception ex)
  {
    MessageBox.Show(ex.ToString());
  }
}


private void myCanvas_SizeChanged(object sender, SizeChangedEventArgs e)
{
  test.Height = ActualHeight;
  Viewer.Height = (ActualHeight);
  Viewer.Width = (ActualWidth);
  //Viewer.FitToHeight();
  Viewer.FitToMaxPagesAcross();
}

private void test_MouseEnter(object sender, MouseEventArgs e)
{
  test.Height = ActualHeight;
}

private void test_MouseLeave(object sender, MouseEventArgs e)
{
  test.Height = 80;
}

private void Image_MouseDown(object sender, MouseButtonEventArgs e)
{
  Image myImage = (Image)sender;
  Viewer.GoToPage(Int32.Parse(myImage.Tag.ToString()));
}

我必须首先从每个页面创建缩略图,还是文档查看器可以显示预览缩略图?

谢谢

0 个答案:

没有答案