none
DocumentViewer怎么不响应鼠标输入消息? RRS feed

  • 问题

  • XAML代码如下:

    <Window x:Class="PPTPlayer.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="XpsDocument" WindowState="Maximized" Height="1920" Width="1080" WindowStartupLocation="CenterScreen" ShowInTaskbar="False" Background="Black">
    <DocumentViewer x:Name="xpsDoc"  Zoom="100"  MouseDown="mousedown"    />
       </Window>

    后台代码如下:

     public MainWindow()
            {
                InitializeComponent();
                 string xpsFilePath = "D:\\work\\PPTPlayer\\12.xps" ;         
                
                     using (XpsDocument xpsDoc = new XpsDocument(_xpsfile, FileAccess.Read))
                {
                    FixedDocumentSequence fs = xpsDoc.GetFixedDocumentSequence();                                           
                                        
                    this.xpsDoc.Document = fs;  
                }
    }
    
    private void mousedown(object sender, MouseButtonEventArgs e)
            {
                int i = 0;
            } 

    点击鼠标的时候,mousedown消息函数无响应,求解??
    2013年12月18日 6:57

答案

  • 您好!

    根据您的代码我在本机创建了一个项目来重现这个问题。我建议您这样来操作,我这边是可以捕获到鼠标事件的,请参考下面的代码:

    XAML Code:

    <Window x:Class="WPFXPSViewerClick.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
        <Grid>
            <DocumentViewer x:Name="XPSPlayer" PreviewMouseDown="XPSPlayer_PreviewMouseDown"/>
        </Grid>
    </Window>

    C# Code:

    public partial class MainWindow : Window
    {
    	public MainWindow()
    	{
    		InitializeComponent();
    	}
    
    	private void Window_Loaded(object sender, RoutedEventArgs e)
    	{
    		using (XpsDocument xpsDoc = new XpsDocument("MSDN Forums.xps", FileAccess.Read))
    		{
    			var fs = xpsDoc.GetFixedDocumentSequence();
    
    			XPSPlayer.Document = fs;
    			XPSPlayer.FitToMaxPagesAcross(1);
    			XPSPlayer.FirstPage();
    		}
    	}
    
    	private void XPSPlayer_PreviewMouseDown(object sender, MouseButtonEventArgs e)
    	{
    		int i = 0;
    	}
    }

    请看下方截图:

    祝您生活愉快!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2013年12月19日 9:55
    版主

全部回复

  • 求人帮忙啊!!

    2013年12月19日 5:58
  • 您好!

    根据您的代码我在本机创建了一个项目来重现这个问题。我建议您这样来操作,我这边是可以捕获到鼠标事件的,请参考下面的代码:

    XAML Code:

    <Window x:Class="WPFXPSViewerClick.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
        <Grid>
            <DocumentViewer x:Name="XPSPlayer" PreviewMouseDown="XPSPlayer_PreviewMouseDown"/>
        </Grid>
    </Window>

    C# Code:

    public partial class MainWindow : Window
    {
    	public MainWindow()
    	{
    		InitializeComponent();
    	}
    
    	private void Window_Loaded(object sender, RoutedEventArgs e)
    	{
    		using (XpsDocument xpsDoc = new XpsDocument("MSDN Forums.xps", FileAccess.Read))
    		{
    			var fs = xpsDoc.GetFixedDocumentSequence();
    
    			XPSPlayer.Document = fs;
    			XPSPlayer.FitToMaxPagesAcross(1);
    			XPSPlayer.FirstPage();
    		}
    	}
    
    	private void XPSPlayer_PreviewMouseDown(object sender, MouseButtonEventArgs e)
    	{
    		int i = 0;
    	}
    }

    请看下方截图:

    祝您生活愉快!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2013年12月19日 9:55
    版主