Skip to content

Commit

Permalink
Update for latest Eto/.NET 8 and get minimal example working
Browse files Browse the repository at this point in the history
  • Loading branch information
cwensley committed Jun 27, 2024
1 parent 0462f24 commit 5021c46
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/Eto.Test.WinUI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Eto.Test.WinUI
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : Application
public partial class App : Microsoft.UI.Xaml.Application
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
Expand All @@ -39,6 +39,7 @@ public App()
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
m_window = new MainWindow();
m_window.Content = new Label { Text = "This is an Eto.Forms Label" };
m_window.Show();
}

Expand Down
10 changes: 5 additions & 5 deletions src/Eto.Test.WinUI/Eto.Test.WinUI.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>Eto.Test.WinUI</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>x86;x64;ARM64</Platforms>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<PublishProfile>win10-$(Platform).pubxml</PublishProfile>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<PublishProfile>win-$(Platform).pubxml</PublishProfile>
<UseWinUI>true</UseWinUI>
<EnableMsixTooling>true</EnableMsixTooling>
<WindowsPackageType>None</WindowsPackageType>
Expand All @@ -24,8 +24,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.3.230502000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.755" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240428000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Eto.Test.WinUI/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<Identity
Name="dd3f09a5-312c-4ed9-abe8-c10fbddb0b38"
Publisher="CN=curti"
Publisher="CN=curtis"
Version="1.0.0.0" />

<mp:PhoneIdentity PhoneProductId="dd3f09a5-312c-4ed9-abe8-c10fbddb0b38" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
Expand Down
14 changes: 7 additions & 7 deletions src/Eto.WinUI/Eto.WinUI.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>Eto.WinUI</RootNamespace>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<UseWinUI>true</UseWinUI>
</PropertyGroup>

<ItemGroup>
<Using Include="Microsoft.UI.Xaml" Alias="mux"/>
<Using Include="Microsoft.UI.Dispatching" Alias="mud"/>
<Using Include="Microsoft.UI.Xaml.Controls" Alias="muc"/>
<Using Include="Microsoft.UI.Xaml" Alias="mux" />
<Using Include="Microsoft.UI.Dispatching" Alias="mud" />
<Using Include="Microsoft.UI.Xaml.Controls" Alias="muc" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.3.230502000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.755" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240428000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
</ItemGroup>

<ItemGroup>
Expand Down
16 changes: 15 additions & 1 deletion src/Eto.WinUI/Forms/Controls/LabelHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@

namespace Eto.WinUI.Forms.Controls
{
internal class LabelHandler : WinUIFrameworkElement<>
public class LabelHandler : WinUIFrameworkElement<muc.TextBlock, Label, Label.ICallback>, Label.IHandler
{
public override mux.FrameworkElement ContainerControl => Control;
protected override muc.TextBlock CreateControl() => new muc.TextBlock();

public TextAlignment TextAlignment { get; set; }
public VerticalAlignment VerticalAlignment { get; set; }
public WrapMode Wrap { get; set; }
public string Text
{
get => Control.Text;
set => Control.Text = value;
}
public Color TextColor { get; set; }
public Font Font { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/Eto.WinUI/Forms/WinUIContainer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Eto.Drawing;
using Eto.Drawing;
using Eto.Forms;

namespace Eto.WinUI.Forms
Expand Down
21 changes: 19 additions & 2 deletions src/Eto.WinUI/Forms/WinUIFrameworkElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
using Eto.Forms;
namespace Eto.WinUI.Forms
{
public abstract partial class WinUIFrameworkElement<TControl, TWidget, TCallback> : WidgetHandler<TControl, TWidget, TCallback>, Control.IHandler
public interface IWinUIFrameworkElement
{
mux.FrameworkElement ContainerControl { get; }
}

public abstract partial class WinUIFrameworkElement<TControl, TWidget, TCallback> : WidgetHandler<TControl, TWidget, TCallback>, Control.IHandler, IWinUIFrameworkElement
where TControl : class
where TWidget : Control
where TCallback : Control.ICallback
{

public abstract mux.FrameworkElement ContainerControl { get; }
public abstract mux.FrameworkElement FocusControl { get; }
public virtual mux.FrameworkElement FocusControl => ContainerControl;


public Color BackgroundColor { get; set; }
public Size Size
Expand Down Expand Up @@ -50,6 +56,12 @@ public virtual bool AllowDrop
get => ContainerControl.AllowDrop;
set => ContainerControl.AllowDrop = value;
}
public bool IsMouseCaptured { get; }

public bool CaptureMouse()
{
throw new NotImplementedException();
}

public virtual void DoDragDrop(DataObject data, DragEffects allowedEffects, Image image, PointF cursorOffset)
{
Expand Down Expand Up @@ -110,6 +122,11 @@ public virtual PointF PointToScreen(PointF point)
//ContainerControl.TransformToVisual()
}

public void ReleaseMouseCapture()
{
throw new NotImplementedException();
}

public virtual void ResumeLayout()
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/Eto.WinUI/Forms/WinUIPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public virtual Control Content
if (_content != value)
{
_content = value;
_border.Child = _content.ToWinUI();
_border.Child = _content.ToNative();
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/Eto.WinUI/Forms/WinUIWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace Eto.WinUI.Forms

public class FormHandler : WinUIWindow<mui.Window, Form, Form.ICallback>, Form.IHandler
{
protected override mui.Window CreateControl() => new mui.Window();

public bool ShowActivated { get; set; }
public bool CanFocus { get; set; }

Expand All @@ -18,7 +20,12 @@ public void Show()
}
}

public class WinUIWindow<TControl, TWidget, TCallback> : WinUIPanel<TControl, TWidget, TCallback>, Window.IHandler //, IWpfWindow, IInputBindingHost
public interface IWinUIWindow
{
mui.Window Control { get; }
}

public class WinUIWindow<TControl, TWidget, TCallback> : WinUIPanel<TControl, TWidget, TCallback>, Window.IHandler, IWinUIWindow//, IInputBindingHost
where TControl : mui.Window
where TWidget : Window
where TCallback : Window.ICallback
Expand Down Expand Up @@ -77,6 +84,8 @@ public override bool Visible
//set => Control..CoreWindow..Visible = value;
}

mui.Window IWinUIWindow.Control => Control;

protected override void Initialize()
{
base.Initialize();
Expand Down
3 changes: 2 additions & 1 deletion src/Eto.WinUI/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Eto.IO;
using Eto.Forms.ThemedControls;
using Eto.WinUI.Forms;
using Eto.WinUI.Forms.Controls;

namespace Eto.WinUI
{
Expand Down Expand Up @@ -77,7 +78,7 @@ public static void AddTo(Eto.Platform p)
//p.Add<GridView.IHandler>(() => new GridViewHandler());
//p.Add<GroupBox.IHandler>(() => new GroupBoxHandler());
//p.Add<ImageView.IHandler>(() => new ImageViewHandler());
//p.Add<Label.IHandler>(() => new LabelHandler());
p.Add<Label.IHandler>(() => new LabelHandler());
//p.Add<LinkButton.IHandler>(() => new LinkButtonHandler());
//p.Add<ListBox.IHandler>(() => new ListBoxHandler());
//p.Add<NumericStepper.IHandler>(() => new NumericStepperHandler());
Expand Down
90 changes: 90 additions & 0 deletions src/Eto.WinUI/WinUIHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using Eto.WinUI.Forms;
using Eto.WinUI.Forms.Controls;
using System.Diagnostics.Metrics;

namespace Eto.Forms
{
public static class WinUIHelpers
{
/// <summary>
/// Gets the native Wpf framework element that contains the Eto.Forms control.
/// </summary>
/// <remarks>
/// Note for some controls, this will not be the 'main' native control.
/// For example, a GridView on OS X will return a NSScrollView instead of a NSTableView, since the table view
/// itself does not scroll.
///
/// When you intend on using the control inside an existing native application, set <paramref name="attach"/> to
/// true so that it can prepare for attaching to the native application by sending OnPreLoad/Load/LoadComplete events.
/// </remarks>
/// <returns>The native control that can be used to add this control to an existing application.</returns>
/// <param name="control">Control to get the native control for.</param>
/// <param name="attach">If set to <c>true</c> the control is to be attached to an existing application, or <c>false</c> to get the native control directly.</param>
public static mux.FrameworkElement ToNative(this Control control, bool attach = false)
{
if (control?.Handler is not IWinUIFrameworkElement handler)
return null;

if (attach && !control.Loaded)
{
control.AttachNative();
// handler.SetScale(false, false);
}
return handler.ContainerControl;
}

/// <summary>
/// Gets the native WPF window of the specified Eto window
/// </summary>
/// <param name="window">Eto window to get the native control for</param>
/// <returns>The native WPF window object.</returns>
public static mux.Window ToNative(this Window window)
{
if (window == null)
return null;
return (window.Handler as IWinUIWindow)?.Control;
}

/// <summary>
/// Wraps the specified <paramref name="nativeControl"/> to an Eto control that can be used directly in Eto.Forms code.
/// </summary>
/// <returns>The eto control wrapper around the native control.</returns>
/// <param name="nativeControl">Native control to wrap.</param>
public static Control ToEto(this mux.FrameworkElement nativeControl)
{
if (nativeControl == null)
return null;
return new NativeControlHost(nativeControl);
}

/// <summary>
/// Wraps the specified WPF <paramref name="window"/> in an Eto control so it can be used as a parent when showing dialogs, etc.
/// </summary>
/// <returns>The eto window wrapper around the native WPF window.</returns>
/// <param name="window">WPF Window to wrap.</param>
public static Window ToEtoWindow(this mux.Window window)
{
if (window == null)
return null;
throw new NotImplementedException();
//return new Form(new NativeFormHandler(window));
}

/// <summary>
/// Wraps a native win32 window in an Eto control so it can be used as a parent when showing dialogs, etc.
/// </summary>
/// <remarks>
/// This is useful when your application is fully native and does not use WinForms or Wpf.
/// </remarks>
/// <returns>The eto window wrapper around the win32 window with the specified handle.</returns>
/// <param name="windowHandle">Handle of the win32 window.</param>
public static Window ToEtoWindow(IntPtr windowHandle)
{
if (windowHandle == IntPtr.Zero)
return null;
throw new NotImplementedException();
//return new Form(new HwndFormHandler(windowHandle));
}

}
}
13 changes: 11 additions & 2 deletions src/Eto.sln
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Eto.macOS", "Eto.Mac\Eto.ma
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Eto.Test.macOS", "..\test\Eto.Test.Mac\Eto.Test.macOS.csproj", "{A5237C58-9EF0-4A34-A1F6-9D4C394A7EE4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.Test.WinUI", "Eto.Test.WinUI\Eto.Test.WinUI.csproj", "{CD5D7DAF-2A03-4F56-B82C-C9472D351617}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Eto.Test.WinUI", "Eto.Test.WinUI\Eto.Test.WinUI.csproj", "{CD5D7DAF-2A03-4F56-B82C-C9472D351617}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eto.WinUI", "Eto.WinUI\Eto.WinUI.csproj", "{35CBA8D2-3395-457E-8EDD-1F9732E77CA1}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Eto.WinUI", "Eto.WinUI\Eto.WinUI.csproj", "{35CBA8D2-3395-457E-8EDD-1F9732E77CA1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -398,6 +398,14 @@ Global
{3511ADDE-7CA8-4F7F-9721-AB48D3913760}.Release|Mac.ActiveCfg = Release|Any CPU
{3511ADDE-7CA8-4F7F-9721-AB48D3913760}.Release|Windows.ActiveCfg = Release|Any CPU
{3511ADDE-7CA8-4F7F-9721-AB48D3913760}.Release|Windows.Build.0 = Release|Any CPU
{3511ADDE-7CA8-4F7F-9721-AB48D3913760}.Release|x64.ActiveCfg = Release|Any CPU
{3511ADDE-7CA8-4F7F-9721-AB48D3913760}.Release|x64.Build.0 = Release|Any CPU
{3511ADDE-7CA8-4F7F-9721-AB48D3913760}.Release|x86.ActiveCfg = Release|Any CPU
{3511ADDE-7CA8-4F7F-9721-AB48D3913760}.Release|x86.Build.0 = Release|Any CPU
{7EBEA53F-6CDC-4DB8-8042-1B048C3502CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7EBEA53F-6CDC-4DB8-8042-1B048C3502CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7EBEA53F-6CDC-4DB8-8042-1B048C3502CF}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{7EBEA53F-6CDC-4DB8-8042-1B048C3502CF}.Debug|ARM64.Build.0 = Debug|Any CPU
{7EBEA53F-6CDC-4DB8-8042-1B048C3502CF}.Debug|Linux.ActiveCfg = Debug|Any CPU
{7EBEA53F-6CDC-4DB8-8042-1B048C3502CF}.Debug|Mac.ActiveCfg = Debug|Any CPU
{7EBEA53F-6CDC-4DB8-8042-1B048C3502CF}.Debug|Windows.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -685,6 +693,7 @@ Global
{CEB897E2-8040-44F5-B41E-DBA9144FEDB2} = {9A93A30F-7627-4F92-ACC4-226BDAD712FB}
{5A16F4FA-C960-46A2-875E-C6CE556F0C36} = {9A93A30F-7627-4F92-ACC4-226BDAD712FB}
{A5237C58-9EF0-4A34-A1F6-9D4C394A7EE4} = {E121B009-AB4B-4585-B3FB-D70E3DF8D3CC}
{CD5D7DAF-2A03-4F56-B82C-C9472D351617} = {E121B009-AB4B-4585-B3FB-D70E3DF8D3CC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FEDB7506-BD8C-41A7-AAA5-6D111D5EA6B8}
Expand Down

0 comments on commit 5021c46

Please sign in to comment.