2017-08-13 5 views
0

Je rencontre un problème avec le blocage de mon contrôle utilisateur. Cela arrive quand je déclenche WindowsFormsHost pour prévisualiser le fichier PDF. Le fichier pdf est toujours en cours d'exécution dans WindowsFormsHost où je peux toujours faire défiler pour l'afficher. Cependant, mes autres commandes (togglebutton, popupbox, etc) ne semblent pas fonctionner.WPF Control Freeze après le déclencheur WindowsFormsHost pour afficher le PDF

Voici le code XAML pour WindowsFormsHost dans mon UserControl

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

Voici le code pour déclencher le WindowsFormsHost appeler fichier PDF à partir UserControl

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

Voici comment je passe le fichier pdf chemin

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

Répondre

0

J'ai suivi votre exemple, aussi bien que possible. Je ne vois pas pourquoi vos contrôles gèlent. Il semble que le problème se situe ailleurs.

I ajouté le contrôle Acrobat Reader à un UserControl "UserControl1"

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); 
    } 
} 
} 

J'ai créé une fenêtre WPF, comme ceci:

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> 

et avec ce code derrière

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!"); 
    } 
} 
} 

Une fois le fichier pdf chargé, je pouvais déclencher l'événement du bouton bascule, afin que Messagebox s'affiche. C'est la raison pour laquelle je parle votre problème vient de n'importe où ailleurs.

+0

J'ai fait cet exemple avant de poster cette question ici. Si c'est seulement ce code seul, je peux lancer le programme. Mais, quand j'essaie de combiner avec mon programme principal, les contrôles comme je l'indique dans le gel des questions sans lancer d'erreur. Je suppose que je continuerai à chercher où est l'erreur. BTW, merci pour l'exemple tho. Cela pourrait aider les autres. Je partagerai la solution ici quand je l'ai résolu plus tard. – OreaSedap