我已经尽可能地效仿了你的榜样。我不明白为什么您的控件冻结了。似乎问题出在其他任何地方。
我将 Acrobat Reader 控件添加到 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);
}
}
}
我创建了一个 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>
后面有这段代码
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 文件后,我可以触发切换按钮事件,因此会显示消息框。这就是为什么我猜你的问题来自其他地方的原因。