Hi,
We are encountering an issue in a WPF application hosted within a WinForms application. The keyboard event is triggered correctly, but the values are not updating properly in the UI.
Here’s the setup:
- Create a WinForms application with a user control.
- Create a WPF application with two XAML files.
- In the WinForms user control, add an element host for the WPF control.
- In the WPF control’s code-behind, create an instance of the main window and display it using button click.
- The main window has a TextBox, but when attempting to type letters or numbers in key board, the TextBox does not update in the UI.
public partial class ReportHost : UserControl
{
private ElementHost _elementHost;
public ReportHost()
{
InitializeComponent();
var wpfControl = new WpfControl();
_elementHost = new ElementHost()
{
Dock = DockStyle.Fill,
};
_elementHost.Child = wpfControl;
Controls.Add(_elementHost);
}
}
<UserControl
x:Class="ShowReport.WpfControl"
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:local="clr-namespace:ShowReport"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<Grid>
<Button Click="ButtonBase_OnClick" Content="Show PDF Viewer" />
</Grid>
</UserControl>
public partial class WpfControl : UserControl
{
public WpfControl()
{
InitializeComponent();
}
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
var window = new MainWindow();
window.Show();
}
}
<Window
x:Class="ShowReport.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:local="clr-namespace:ShowReport"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="MainWindow"
Width="800"
Height="450"
mc:Ignorable="d">
<TextBox Height="100" Width="200"/>
</Window>
Could you kindly check the code snippet and suggest a solution to resolve this issue?