2017-08-13 63 views
0

我有我的用戶控制凍結問題。當我觸發WindowsFormsHost預覽PDF文件時發生。 PDF文件仍然在WindowsFormsHost中運行,我仍然可以滾動查看它。但是,我的其他控件(togglebutton,popupbox等)似乎並沒有工作。WPF控件凍結後WindowsFormsHost觸發器查看PDF

這裏是我的用戶

<Grid Margin="0,0,203,0"> 
    <WindowsFormsHost x:Name="ViewPDFWinForm" HorizontalAlignment="Left" Height="444" VerticalAlignment="Top" Width="708"/> 
</Grid>  

這裏WindowsFormsHost的XAML代碼被觸發WindowsFormsHost從用戶控件

PreviewReportPDF uc = new PreviewReportPDF(ReportGenerator.ReportPath); 
this.ViewPDFWinForm.Child = uc; 

這裏叫PDF文件中的代碼是我通過PDF文件路徑

public PreviewReportPDF(string filepath) 
    { 
     InitializeComponent(); 
     this.axAcroPDF1.LoadFile(filepath); 
     this.axAcroPDF1.setZoom(63); 
    } 

回答

0

我跟着你的例子,盡我所能。我看不出你爲什麼控制凍結。 似乎這個問題位於其他地方。

我加入了Acrobat Reader軟件控制來

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Drawing; 
using System.Data; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 

namespace WpfApplication9 
{ 
public partial class UserControl1 : UserControl 
{ 

    public UserControl1(string filepath) 
    { 
     InitializeComponent(); 
     this.axAcroPDF1.LoadFile(filepath); 
     this.axAcroPDF1.setZoom(63); 
    } 
} 
} 

我創建了一個WPF窗口,這樣的用戶控件 「的UserControl1」:

Window x:Class="WpfApplication9.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:local="clr-namespace:WpfApplication9" 
    mc:Ignorable="d" 
    Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded"> 
<Grid> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition /> 
     <ColumnDefinition /> 
    </Grid.ColumnDefinitions> 
    <WindowsFormsHost x:Name="host"/> 
    <ToggleButton Content="Toggle" Grid.Column="1" Click="ToggleButton_Click" /> 

</Grid> 
</Window> 

,並與後面

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Data; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Imaging; 
using System.Windows.Navigation; 
using System.Windows.Shapes; 
using System.IO; 
using Microsoft.VisualBasic; 

namespace WpfApplication9 
{ 
/// <summary> 
/// Interaktionslogik für MainWindow.xaml 
/// </summary> 
public partial class MainWindow : Window 
{ 
    public MainWindow() 
    { 
     InitializeComponent(); 
    } 

    private void Window_Loaded(object sender, RoutedEventArgs e) 
    { 
     UserControl1 uc = new UserControl1(System.IO.Path.Combine(Microsoft.VisualBasic.FileIO.SpecialDirectories.Desktop, "Test.pdf")); 
     this.host.Child = uc; 
    } 

    private void ToggleButton_Click(object sender, RoutedEventArgs e) 
    { 
     MessageBox.Show("Hallo welt!"); 
    } 
} 
} 
驗證碼

在加載pdf文件後,我可以觸發切換按鈕事件,因此顯示了Messagebox。這就是爲什麼我提出你的問題來自其他地方的原因。

+0

我在這裏發佈這個問題之前完成了這個例子。如果僅僅是這個代碼,我可以運行程序。但是,當我嘗試與我的主程序結合使用時,像我在問題中聲明的控件凍結而沒有發生任何錯誤。我想我會繼續尋找錯誤的地方。順便說一句,謝謝你的例子。它可能會幫助其他人。當我稍後解決時,我會在這裏分享解決方案。 – OreaSedap