Skip to content

Commit a05d5ee

Browse files
committed
chore: Custom window sample
1 parent b4f42aa commit a05d5ee

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<Window
3+
x:Class="WindowingSamples.CustomWindow"
4+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6+
xmlns:controls="using:WindowingSamples.Controls"
7+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
mc:Ignorable="d">
10+
11+
<Grid x:Name="RootGrid">
12+
<Grid.RowDefinitions>
13+
<RowDefinition Height="Auto" />
14+
<RowDefinition Height="*" />
15+
</Grid.RowDefinitions>
16+
<controls:WindowTitleControl Text="Custom window" Glyph="&#xE161;" />
17+
18+
19+
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1" Spacing="8">
20+
<TextBlock x:Name="WindowText" HorizontalAlignment="Center" Text="This is custom window" FontSize="40" />
21+
<Button HorizontalAlignment="Center" Click="CloseClick">Close</Button>
22+
</StackPanel>
23+
</Grid>
24+
</Window>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Microsoft.UI.Windowing;
2+
using Windows.UI;
3+
4+
namespace WindowingSamples;
5+
6+
/// <summary>
7+
/// An empty window that can be used on its own or navigated to within a Frame.
8+
/// </summary>
9+
public sealed partial class CustomWindow : Window
10+
{
11+
private static int _customWindowCounter = 0;
12+
13+
public CustomWindow()
14+
{
15+
InitializeComponent();
16+
17+
var random = Random.Shared;
18+
RootGrid.Background = new SolidColorBrush(
19+
Color.FromArgb(
20+
255,
21+
(byte)random.Next(0,150),
22+
(byte)random.Next(0, 150),
23+
(byte)random.Next(0,150)));
24+
25+
var text = $"Custom Window {++_customWindowCounter}";
26+
Title = text;
27+
WindowText.Text = text;
28+
}
29+
30+
public void CloseClick(object sender, RoutedEventArgs args) => Close();
31+
}

0 commit comments

Comments
 (0)