WPF add System.Windows.Forms.PropertyGrid via WindowsFormsHost
1.Add reference System.Windows.Forms.dll;
2.Add reference C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsFormsIntegration.dll
3.
//xaml <Window x:Class="WpfApp131.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:WpfApp131" WindowState="Maximized" mc:Ignorable="d" Loaded="Window_Loaded" Title="MainWindow" Height="450" Width="800"> <Grid x:Name="grid"> </Grid> </Window> //cs 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.Windows.Forms.Integration; using System.Windows.Forms; namespace WpfApp131 { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { WindowsFormsHost host = new WindowsFormsHost(); PropertyGrid propertyGrid = new PropertyGrid(); host.Child=propertyGrid; grid.Children.Add(host); propertyGrid.SelectedObject = this; } } }



浙公网安备 33010602011771号