Skip to content

Instantly share code, notes, and snippets.

@vzarytovskii
Created September 15, 2023 14:05
Show Gist options
  • Save vzarytovskii/749745e0d0c1fc4021ada601318c2c5d to your computer and use it in GitHub Desktop.
Save vzarytovskii/749745e0d0c1fc4021ada601318c2c5d to your computer and use it in GitHub Desktop.
F# Xaml demo, please somebody kill me
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
<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>
<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