WindowsFormsHost触发后WPF控件冻结以查看PDF
我的用户控件冻结有问题。这是在我触发WindowsFormsHost预览PDF文件时发生的。pdf文件仍然在WindowsFormsHost中运行,我仍然可以滚动查看它。然而,我的其他控件(togglebutton、popupbox等)似乎不起作用 以下是我的UserControl中WindowsFormsHost的XAML代码WindowsFormsHost触发后WPF控件冻结以查看PDF,wpf,pdf,windowsformshost,axacropdf,Wpf,Pdf,Windowsformshost,Axacropdf,我的用户控件冻结有问题。这是在我触发WindowsFormsHost预览PDF文件时发生的。pdf文件仍然在WindowsFormsHost中运行,我仍然可以滚动查看它。然而,我的其他控件(togglebutton、popupbox等)似乎不起作用 以下是我的UserControl中WindowsFormsHost的XAML代码 <Grid Margin="0,0,203,0"> <WindowsFormsHost x:Name="ViewPDFWinForm" Horiz
<Grid Margin="0,0,203,0">
<WindowsFormsHost x:Name="ViewPDFWinForm" HorizontalAlignment="Left" Height="444" VerticalAlignment="Top" Width="708"/>
</Grid>
PreviewReportPDF uc = new PreviewReportPDF(ReportGenerator.ReportPath);
this.ViewPDFWinForm.Child = uc;
下面是我如何传递pdf文件路径的
public PreviewReportPDF(string filepath)
{
InitializeComponent();
this.axAcroPDF1.LoadFile(filepath);
this.axAcroPDF1.setZoom(63);
}
我已经尽我所能以你为榜样了。我看不出你的控制装置为什么冻结了。 问题似乎在其他任何地方 我将Acrobat Reader控件添加到UserControl“UserControl1”中 我创建了一个WPF窗口,如下所示:
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>
windowx: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命名空间:WpfApplication9”
mc:Ignorable=“d”
Title=“MainWindow”Height=“350”Width=“525”Loaded=“Window\u Loaded”>
而这个代码就在后面
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!");
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
使用System.IO;
使用Microsoft.VisualBasic;
命名空间WpfApplication9
{
///
///Interaktionslogik für MainWindow.xaml
///
公共部分类主窗口:窗口
{
公共主窗口()
{
初始化组件();
}
已加载私有无效窗口(对象发送器、路由目标)
{
UserControl1 uc=新的UserControl1(System.IO.Path.Combine(Microsoft.VisualBasic.FileIO.SpecialDirectories.Desktop,“Test.pdf”);
this.host.Child=uc;
}
私有无效切换按钮\单击(对象发送方,路由目标)
{
MessageBox.Show(“你好!”);
}
}
}
加载pdf文件后,我可以触发切换按钮事件,因此显示Messagebox。这就是我认为你的问题来自其他任何地方的原因。我已经尽我所能以你为榜样。我看不出你的控制装置为什么冻结了。 问题似乎在其他任何地方 我将Acrobat Reader控件添加到UserControl“UserControl1”中 我创建了一个WPF窗口,如下所示:
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>
windowx: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命名空间:WpfApplication9”
mc:Ignorable=“d”
Title=“MainWindow”Height=“350”Width=“525”Loaded=“Window\u Loaded”>
而这个代码就在后面
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!");
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
使用System.IO;
使用Microsoft.VisualBasic;
命名空间WpfApplication9
{
///
///Interaktionslogik für MainWindow.xaml
///
公共部分类主窗口:窗口
{
公共主窗口()
{
初始化组件();
}
已加载私有无效窗口(对象发送器、路由目标)
{
UserControl1 uc=新的UserControl1(System.IO.Path.Combine(Microsoft.VisualBasic.FileIO.SpecialDirectories.Desktop,“Test.pdf”);
this.host.Child=uc;
}
私有无效切换按钮\单击(对象发送方,路由目标)
{
MessageBox.Show(“你好!”);
}
}
}
加载pdf文件后,我可以触发切换按钮事件,因此显示Messagebox。这就是为什么我认为你的问题来自其他任何地方。我在这里发布这个问题之前已经做了这个例子。如果仅仅是这段代码,我就可以运行这个程序。但是,当我尝试与主程序结合时,像我在问题中所述的控件冻结,不会抛出任何错误。我想我会继续寻找错误所在。顺便说一句,谢谢你的例子。它可能会帮助其他人。当我稍后解决这个问题时,我会在这里分享解决方案。在我将这个问题发布到这里之前,我已经完成了这个示例。如果仅仅是这段代码,我就可以运行这个程序。但是,当我尝试与主程序结合时,像我在问题中所述的控件冻结,不会抛出任何错误。我想我会继续寻找错误所在。顺便说一句,谢谢你的例子。它可能会帮助其他人。当我稍后解决它时,我将在这里分享解决方案。