Skip to content

Commit

Permalink
Merge commit 'eef15c87d0d3d9338725810f311df18f370bab2d'
Browse files Browse the repository at this point in the history
  • Loading branch information
lindexi committed Jun 19, 2024
2 parents 1ecc806 + eef15c8 commit 48593d0
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
21 changes: 21 additions & 0 deletions WPFDemo/NocejefiWeyufilareewe/NocejefiWeyufilareewe.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0-windows10.0.19041</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PlatformTarget>x86</PlatformTarget>
<RuntimeIdentifiers>win10-x86;win10-x64</RuntimeIdentifiers>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<UseWinUI>true</UseWinUI>
<WindowsPackageType>None</WindowsPackageType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.3.230331000" />
</ItemGroup>


</Project>
25 changes: 25 additions & 0 deletions WPFDemo/NocejefiWeyufilareewe/NocejefiWeyufilareewe.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34607.119
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NocejefiWeyufilareewe", "NocejefiWeyufilareewe.csproj", "{098673E0-7899-4746-859D-910F4F48532C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{098673E0-7899-4746-859D-910F4F48532C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{098673E0-7899-4746-859D-910F4F48532C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{098673E0-7899-4746-859D-910F4F48532C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{098673E0-7899-4746-859D-910F4F48532C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C392047D-8433-4484-BC22-976C5FE6CC95}
EndGlobalSection
EndGlobal
68 changes: 68 additions & 0 deletions WPFDemo/NocejefiWeyufilareewe/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml;

namespace NocejefiWeyufilareewe;

public class App : Application
{
public event EventHandler<LaunchActivatedEventArgs>? Launched;

protected override void OnLaunched(LaunchActivatedEventArgs args)
{
Launched?.Invoke(this, args);
}
}

internal class Program
{
static void Main(string[] args)
{
global::WinRT.ComWrappersSupport.InitializeComWrappers();
global::Microsoft.UI.Xaml.Application.Start((p) =>
{
var app = new App();
app.Launched += (_, e) =>
{
var window = new Window()
{
Title = "控制台创建应用"
};
window.Content = new Grid()
{
Children =
{
new TextBlock()
{
Text = "控制台应用",
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
},
new Button()
{
Content = "点击",
Margin = new Thickness(0, 100, 0, 0),
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
}.Do(button => button.Click += (s, _) =>
{
// System.InvalidCastException:“Specified cast is not valid.”
// https://stackoverflow.com/questions/73936140/how-to-get-the-window-hosting-a-uielement-instance
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(s);
})
}
};
window.Activate();
};
});
}
}

static class CsharpMarkup
{
public static T Do<T>(this T element, Action<T> action) where T : UIElement
{
action(element);

return element;
}
}

0 comments on commit 48593d0

Please sign in to comment.