Created
September 15, 2023 14:05
-
-
Save vzarytovskii/749745e0d0c1fc4021ada601318c2c5d to your computer and use it in GitHub Desktop.
F# Xaml demo, please somebody kill me
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Project | |
open System | |
open System.Windows | |
open System.IO | |
open System.Windows.Markup | |
open System.Windows.Controls | |
open System.Reflection | |
let contentAsXamlObjectFromAssembly (assemblyName: string, xamlFilelName: string) = | |
let assembly = Assembly.Load(assemblyName) | |
let res = | |
assembly.GetManifestResourceNames() | |
|> Array.filter (fun x -> x.ToLower().IndexOf(xamlFilelName.ToLower()) > -1) | |
match res.Length = 1 with | |
| true -> | |
let mySr = new StreamReader(assembly.GetManifestResourceStream(res.[0])) | |
XamlReader.Load(mySr.BaseStream) | |
| false -> null | |
let mutable this : Window = contentAsXamlObjectFromAssembly(Assembly.GetExecutingAssembly().FullName,"Project.xaml") :?> Window | |
[<STAThread>] | |
[<EntryPoint>] | |
do (new Application()).Run(this) |> ignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>WinExe</OutputType> | |
<TargetFramework>net8.0-windows</TargetFramework> | |
<UseWPF>true</UseWPF> | |
</PropertyGroup> | |
<ItemGroup> | |
<Page Remove="Project.xaml" /> | |
</ItemGroup> | |
<ItemGroup> <EmbeddedResource Include="Project.xaml" /> | |
<Compile Include="Project.fs" /> | |
</ItemGroup> | |
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:ShowImage="clr-namespace:Project;assembly=Project" | |
MinWidth="256" MinHeight="266" Title="Kill me pls" SizeToContent="WidthAndHeight" > | |
<Grid x:Name="grid"> | |
</Grid> | |
</Window> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment