Notitie
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen u aan te melden of de directory te wijzigen.
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen de mappen te wijzigen.
WPF biedt veel bedieningselementen met een uitgebreide set van functionaliteiten. Mogelijk wilt u echter soms Windows Forms-besturingselementen gebruiken op uw WPF-pagina's. U hebt bijvoorbeeld een aanzienlijke investering in bestaande Besturingselementen voor Windows Forms of u hebt een Besturingselement voor Windows Forms dat unieke functionaliteit biedt.
In dit overzicht ziet u hoe u een Besturingselement voor Windows Forms System.Windows.Forms.MaskedTextBox host op een WPF-pagina met behulp van code.
Zie Hosting a Windows Forms Control in WPF Samplevoor een volledig codeoverzicht van de taken in deze handleiding.
Vereiste voorwaarden
U hebt Visual Studio nodig om deze walkthrough te voltooien.
Het Besturingselement Windows Forms hosten
Om het MaskedTextBox-besturingselement te beheren
Maak een WPF-toepassingsproject met de naam
HostingWfInWpf.Voeg verwijzingen toe aan de volgende assemblies.
WindowsFormsIntegration
System.Windows.Forms
Open MainWindow.xaml in de WPF Designer.
Geef het Grid element een naam
grid1.<Grid Name="grid1"> </Grid>Selecteer in de ontwerpweergave of de XAML-weergave het element Window.
Klik in het venster Eigenschappen op het tabblad Gebeurtenissen.
Dubbelklik op de gebeurtenis Loaded.
Voeg de volgende code in om de Loaded gebeurtenis af te handelen.
private void Window_Loaded(object sender, RoutedEventArgs e) { // Create the interop host control. System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost(); // Create the MaskedTextBox control. MaskedTextBox mtbDate = new MaskedTextBox("00/00/0000"); // Assign the MaskedTextBox control as the host control's child. host.Child = mtbDate; // Add the interop host control to the Grid // control's collection of child controls. this.grid1.Children.Add(host); }Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs) ' Create the interop host control. Dim host As New System.Windows.Forms.Integration.WindowsFormsHost() ' Create the MaskedTextBox control. Dim mtbDate As New MaskedTextBox("00/00/0000") ' Assign the MaskedTextBox control as the host control's child. host.Child = mtbDate ' Add the interop host control to the Grid ' control's collection of child controls. Me.grid1.Children.Add(host) End SubVoeg bovenaan het bestand de volgende
Importsofusinginstructie toe.using System.Windows.Forms;Imports System.Windows.FormsDruk op F5- om de toepassing te bouwen en uit te voeren.
Zie ook
- ElementHost
- WindowsFormsHost
- XAML ontwerpen in Visual Studio
- walkthrough: een Besturingselement voor Windows Forms hosten in WPF met behulp van XAML-
- Handleiding: Een Windows Forms Composite Control hosten in WPF
- Walkthrough: Een WPF Composite Control hosten in Windows Forms
- Windows Forms-besturingselementen en gelijkwaardige WPF-besturingselementen
- Een Besturingselement voor Windows Forms hosten in WPF Sample
.NET Desktop feedback