Add the PropertyGrid to the host, and the host to the WPF Grid


SUBMITTED BY: abmrasel

DATE: June 26, 2017, 4:32 p.m.

FORMAT: C++

SIZE: 1.3 kB

HITS: 392

  1. Add the PropertyGrid to the host, and the host to the WPF Grid
  2. ===============================================================
  3. <Window x:Class="WpfApplication1.Window1"
  4. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  5. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  6. Title="Hosting a Windows Forms Property Grid in WPF"
  7. Loaded="Window_Loaded">
  8. <Grid Name="grid"/>
  9. </Window>
  10. //File:Window.xaml.cs
  11. using System;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.Windows.Data;
  15. using System.Windows.Documents;
  16. using System.Windows.Media;
  17. using System.Windows.Shapes;
  18. namespace WpfApplication1
  19. {
  20. public partial class Window1 : Window
  21. {
  22. public Window1()
  23. {
  24. InitializeComponent();
  25. }
  26. private void Window_Loaded(object sender, RoutedEventArgs e)
  27. {
  28. System.Windows.Forms.Integration.WindowsFormsHost host =
  29. new System.Windows.Forms.Integration.WindowsFormsHost();
  30. System.Windows.Forms.PropertyGrid propertyGrid =
  31. new System.Windows.Forms.PropertyGrid();
  32. host.Child = propertyGrid;
  33. grid.Children.Add(host);
  34. propertyGrid.SelectedObject = this;
  35. }
  36. }
  37. }

comments powered by Disqus