Created
November 19, 2024 16:23
-
-
Save SMSAgentSoftware/e27996d9f922f0e8f45414d85e0889b9 to your computer and use it in GitHub Desktop.
A simple WPF app example demonstrating the Fluent theme. Requires .Net 9 and PowerShell 7.5+
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
# Define the xaml code for the window | |
[xml]$xaml = @' | |
<Window | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
Title="Let's Eat!" | |
ThemeMode="Dark" | |
SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen" > | |
<Grid> | |
<TabControl Margin="5"> | |
<TabItem> | |
<TabItem.Header> | |
<StackPanel Orientation="Horizontal"> | |
<TextBlock FontFamily="{StaticResource SymbolThemeFontFamily}" Text="" VerticalAlignment="Center" Foreground="{DynamicResource AccentTextFillColorPrimaryBrush}"/> | |
<TextBlock Text="Food" Margin="5" Foreground="{DynamicResource AccentTextFillColorPrimaryBrush}"/> | |
</StackPanel> | |
</TabItem.Header> | |
<StackPanel Margin="5" > | |
<TextBlock Text="Food" FontSize="20" FontWeight="Bold" /> | |
<TextBlock Text="Food is any substance consumed to provide nutritional support for an organism." /> | |
<Expander Header="Different types of food" Margin="5" Background="{DynamicResource AccentTextFillColorTertiaryBrush}"> | |
<ListView> | |
<ListViewItem Content="Healthy"/> | |
<ListViewItem Content="Unhealthy"/> | |
</ListView> | |
</Expander> | |
<StackPanel Orientation="Horizontal" Background="{DynamicResource SolidBackgroundFillColorTeriaryBrush}"> | |
<Label Content="Click on a food item to know more" Background="{DynamicResource SolidBackgroundFillColorTeriaryBrush}"/> | |
</StackPanel> | |
<StackPanel Orientation="Horizontal"> | |
<Button Name="Eggs" Content="Eggs" Style="{DynamicResource AccentButtonStyle}" Margin="5"/> | |
<Button Name="Butter" Content="Butter" Margin="5"/> | |
<Button Name="Rice" Content="Rice" Style="{DynamicResource AccentButtonStyle}" Margin="5"/> | |
<Button Name="Beans" Content="Beans" Margin="5"/> | |
</StackPanel> | |
<Slider Width="500" Margin="3" HorizontalAlignment="Left" VerticalAlignment="Center" Maximum="100" Minimum="0"/> | |
</StackPanel> | |
</TabItem> | |
<TabItem > | |
<TabItem.Header> | |
<StackPanel Orientation="Horizontal"> | |
<TextBlock FontFamily="{StaticResource SymbolThemeFontFamily}" Text="" VerticalAlignment="Center" Foreground="{DynamicResource AccentTextFillColorPrimaryBrush}"/> | |
<TextBlock Text="Drink" Margin="5" Foreground="{DynamicResource AccentTextFillColorPrimaryBrush}"/> | |
</StackPanel> | |
</TabItem.Header> | |
<StackPanel Margin="5"> | |
<TextBlock Text="Drink" FontSize="20" FontWeight="Bold" /> | |
<TextBlock Text="A drink is a liquid intended for human consumption." /> | |
</StackPanel> | |
</TabItem> | |
</TabControl> | |
</Grid> | |
</Window> | |
'@ | |
# Load the WPF assembly | |
Add-Type -AssemblyName PresentationFramework | |
# Load the window and named elements as variables in a hash table | |
$UI = [System.Collections.Hashtable]::Synchronized(@{}) | |
$UI.Window = [System.Windows.Markup.XamlReader]::Load((New-Object -TypeName System.Xml.XmlNodeReader -ArgumentList $xaml)) | |
$xaml.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | | |
ForEach-Object -Process { | |
$UI.$($_.Name) = $UI.Window.FindName($_.Name) | |
} | |
# Bring window to the fore | |
$UI.Window.Add_Loaded({ | |
$This.Activate() | |
}) | |
# Add a click event to the Eggs button | |
$UI.Eggs.Add_Click({ | |
## Pop a simple wscript notification | |
$wshell = New-Object -ComObject Wscript.Shell | |
$wshell.Popup("Eggs are a good source of protein and other nutrients",0,"Eggs",0x1) | |
}) | |
# Show the window | |
[void]$UI.Window.ShowDialog() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment