2017-08-13 39 views
0

ユーザーコントロールのフリーズに問題があります。 WindowsFormsHostを起動してPDFファイルをプレビューするときに発生します。私はまだそれを表示するためにスクロールすることができますWindowsFormsHostで実行されているPDFファイル。しかし、私の他のコントロール(トグルボタン、ポップアップボックスなど)は動作していないようです。ここでWPFコントロールWindowsFormsHostトリガー後にフリーズしてPDFを表示する

はにWindowsFormsHostのためのXAMLコードはここに私のUserControlに

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

です。ここのUserControl

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

からPDFファイルを呼び出すためにWindowsFormsHostをトリガーするためのコードは、私はpdfファイルを渡す方法です経路

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

答えて

0

私はできる限り良いあなたの例に従っています。なぜコントロールが凍っているのか分かりません。 問題はどこにでもあるようです。

私は、私はこのようなWPFウィンドウ、作成したユーザーコントロール "の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); 
    } 
} 
} 

をAcrobat Readerのコントロールを追加しました:

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

私はこの質問をここに掲載する前にこの例を行っています。もしこのコードだけであれば、私はプログラムを実行することができます。しかし、私が私のメインプログラムと結合しようとすると、私のようなコントロールは何のエラーも投げずにフリーズの問題に言います。私は間違いがどこにあるかを見続けると思います。ところで、例のおかげでtho。それは他人を助けるかもしれない。後で解決するときに私はここで解決策を共有します。 – OreaSedap

関連する問題