From c406b51cd01d6c44994fcbf3383934758b274ad2 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Tue, 23 May 2023 02:53:41 -0400 Subject: [PATCH] Remove WPF integration after internal discussion --- .../WindowsInteropTest/EmbedToWpfDemo.xaml | 31 ----- .../WindowsInteropTest/EmbedToWpfDemo.xaml.cs | 29 ----- samples/interop/WindowsInteropTest/Program.cs | 2 +- .../SelectorForm.Designer.cs | 76 ----------- .../WindowsInteropTest/SelectorForm.cs | 30 ----- .../WindowsInteropTest/SelectorForm.resx | 120 ------------------ .../Wpf/WpfAvaloniaHost.cs | 84 ------------ 7 files changed, 1 insertion(+), 371 deletions(-) delete mode 100644 samples/interop/WindowsInteropTest/EmbedToWpfDemo.xaml delete mode 100644 samples/interop/WindowsInteropTest/EmbedToWpfDemo.xaml.cs delete mode 100644 samples/interop/WindowsInteropTest/SelectorForm.Designer.cs delete mode 100644 samples/interop/WindowsInteropTest/SelectorForm.cs delete mode 100644 samples/interop/WindowsInteropTest/SelectorForm.resx delete mode 100644 src/Windows/Avalonia.Win32.Interoperability/Wpf/WpfAvaloniaHost.cs diff --git a/samples/interop/WindowsInteropTest/EmbedToWpfDemo.xaml b/samples/interop/WindowsInteropTest/EmbedToWpfDemo.xaml deleted file mode 100644 index 4d043f780c..0000000000 --- a/samples/interop/WindowsInteropTest/EmbedToWpfDemo.xaml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/samples/interop/WindowsInteropTest/EmbedToWpfDemo.xaml.cs b/samples/interop/WindowsInteropTest/EmbedToWpfDemo.xaml.cs deleted file mode 100644 index e21ed72fa5..0000000000 --- a/samples/interop/WindowsInteropTest/EmbedToWpfDemo.xaml.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Windows; -using Avalonia; -using Avalonia.Controls; -using ControlCatalog; - -namespace WindowsInteropTest -{ - public partial class EmbedToWpfDemo - { - public EmbedToWpfDemo() - { - InitializeComponent(); - Host.Content = new MainView(); - - var btn = (Button) RightBtn.Content!; - btn.Click += delegate - { - btn.Content += "!"; - }; - - Loaded += OnLoaded; - } - - private void OnLoaded(object sender, RoutedEventArgs e) - { - TopLevel.GetTopLevel((MainView)Host.Content)!.AttachDevTools(); - } - } -} diff --git a/samples/interop/WindowsInteropTest/Program.cs b/samples/interop/WindowsInteropTest/Program.cs index 830082aafe..4ebb88642b 100644 --- a/samples/interop/WindowsInteropTest/Program.cs +++ b/samples/interop/WindowsInteropTest/Program.cs @@ -18,7 +18,7 @@ namespace WindowsInteropTest .UseWin32() .UseSkia() .SetupWithoutStarting(); - System.Windows.Forms.Application.Run(new SelectorForm()); + System.Windows.Forms.Application.Run(new EmbedToWinFormsDemo()); } } } diff --git a/samples/interop/WindowsInteropTest/SelectorForm.Designer.cs b/samples/interop/WindowsInteropTest/SelectorForm.Designer.cs deleted file mode 100644 index 7cf402913e..0000000000 --- a/samples/interop/WindowsInteropTest/SelectorForm.Designer.cs +++ /dev/null @@ -1,76 +0,0 @@ -namespace WindowsInteropTest -{ - partial class SelectorForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.btnEmbedToWinForms = new System.Windows.Forms.Button(); - this.btnEmbedToWpf = new System.Windows.Forms.Button(); - this.SuspendLayout(); - // - // btnEmbedToWinForms - // - this.btnEmbedToWinForms.Location = new System.Drawing.Point(12, 12); - this.btnEmbedToWinForms.Name = "btnEmbedToWinForms"; - this.btnEmbedToWinForms.Size = new System.Drawing.Size(201, 86); - this.btnEmbedToWinForms.TabIndex = 0; - this.btnEmbedToWinForms.Text = "Embed to WinForms"; - this.btnEmbedToWinForms.UseVisualStyleBackColor = true; - this.btnEmbedToWinForms.Click += new System.EventHandler(this.btnEmbedToWinForms_Click); - // - // btnEmbedToWpf - // - this.btnEmbedToWpf.Location = new System.Drawing.Point(219, 12); - this.btnEmbedToWpf.Name = "btnEmbedToWpf"; - this.btnEmbedToWpf.Size = new System.Drawing.Size(201, 86); - this.btnEmbedToWpf.TabIndex = 1; - this.btnEmbedToWpf.Text = "Embed to WPF"; - this.btnEmbedToWpf.UseVisualStyleBackColor = true; - this.btnEmbedToWpf.Click += new System.EventHandler(this.btnEmbedToWpf_Click); - // - // SelectorForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(432, 284); - this.Controls.Add(this.btnEmbedToWpf); - this.Controls.Add(this.btnEmbedToWinForms); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; - this.MaximizeBox = false; - this.Name = "SelectorForm"; - this.Text = "Interop"; - this.ResumeLayout(false); - - } - - #endregion - - private System.Windows.Forms.Button btnEmbedToWinForms; - private System.Windows.Forms.Button btnEmbedToWpf; - } -} - diff --git a/samples/interop/WindowsInteropTest/SelectorForm.cs b/samples/interop/WindowsInteropTest/SelectorForm.cs deleted file mode 100644 index 6430694f79..0000000000 --- a/samples/interop/WindowsInteropTest/SelectorForm.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace WindowsInteropTest -{ - public partial class SelectorForm : Form - { - public SelectorForm() - { - InitializeComponent(); - } - - private void btnEmbedToWinForms_Click(object sender, EventArgs e) - { - new EmbedToWinFormsDemo().ShowDialog(this); - } - - private void btnEmbedToWpf_Click(object sender, EventArgs e) - { - new EmbedToWpfDemo().ShowDialog(); - } - } -} diff --git a/samples/interop/WindowsInteropTest/SelectorForm.resx b/samples/interop/WindowsInteropTest/SelectorForm.resx deleted file mode 100644 index 1af7de150c..0000000000 --- a/samples/interop/WindowsInteropTest/SelectorForm.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/src/Windows/Avalonia.Win32.Interoperability/Wpf/WpfAvaloniaHost.cs b/src/Windows/Avalonia.Win32.Interoperability/Wpf/WpfAvaloniaHost.cs deleted file mode 100644 index d9dfa6b5d0..0000000000 --- a/src/Windows/Avalonia.Win32.Interoperability/Wpf/WpfAvaloniaHost.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using System.Windows; -using System.Windows.Interop; -using System.Windows.Markup; -using Avalonia.Controls.Embedding; -using Avalonia.Win32.Interop; -using AvControl = Avalonia.Controls.Control; - -namespace Avalonia.Win32.Interoperability; - -/// -/// An element that allows you to host a Avalonia control on a WPF page. -/// -[ContentProperty("Content")] -public class WpfAvaloniaHost : HwndHost -{ - private EmbeddableControlRoot? _root; - private AvControl? _content; - - /// - /// Initializes a new instance of the class. - /// - public WpfAvaloniaHost() - { - DataContextChanged += AvaloniaHwndHost_DataContextChanged; - } - - private void AvaloniaHwndHost_DataContextChanged(object sender, System.Windows.DependencyPropertyChangedEventArgs e) - { - if (Content != null) - { - Content.DataContext = e.NewValue; - } - } - - /// - /// Gets or sets the Avalonia control hosted by the element. - /// - public AvControl? Content - { - get => _content; - set - { - if (_content != value) - { - _content = value; - if (_root is not null) - { - _root.Content = value; - } - if (value != null) - { - value.DataContext = DataContext; - } - } - } - } - - /// - protected override HandleRef BuildWindowCore(HandleRef hwndParent) - { - _root = new EmbeddableControlRoot(); - _root.Content = _content; - _root.Prepare(); - _root.Renderer.Start(); - - var handle = _root.TryGetPlatformHandle()?.Handle - ?? throw new InvalidOperationException("WpfAvaloniaHost is unable to create EmbeddableControlRoot."); - - if (PresentationSource.FromVisual(this) is HwndSource source) - { - _ = UnmanagedMethods.SetParent(handle, source.Handle); - } - - return new HandleRef(_root, handle); - } - - /// - protected override void DestroyWindowCore(HandleRef hwnd) - { - _root?.Dispose(); - } -}