Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add XAML Fundamentals section with pages and examples #1661

Open
wants to merge 63 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
01009d7
**feat**: Add XAML Fundamentals section with pages, examples, assets,…
Zakariathr22 Nov 21, 2024
0343c59
Update BindingPage: Refactor some examples to use x:Bind, add x:Bind …
Zakariathr22 Nov 22, 2024
54d2944
Update some examples and their sample code for improved clarity and u…
Zakariathr22 Nov 22, 2024
014506c
feat: Improve "x:Bind and Binding differences table" in `BindingPage.…
Zakariathr22 Nov 24, 2024
b916465
fix: correct unnecessary capitalization
Zakariathr22 Nov 26, 2024
7cfce1f
Update navigation symbol in InfoBar message on ThemeResourcesPage
Zakariathr22 Nov 27, 2024
85aab8a
feat: enhance BindingPage with new examples, design improvements, and…
Zakariathr22 Nov 29, 2024
dafd023
feat: add BasedOn property example and improve design in XamlStylesPage
Zakariathr22 Nov 29, 2024
fbcd5af
chore: minor design tweaks for TemplatesPage and ThemeResourcesPage
Zakariathr22 Nov 29, 2024
a96c434
chore: update x:Bind vs Binding table and add documentation links
Zakariathr22 Nov 29, 2024
a2a2c02
fix: update example header in BindingPage to replace `Converter` with…
Zakariathr22 Nov 30, 2024
381ab05
chore: remove unnecessary italics in XamlStylesPage
Zakariathr22 Nov 30, 2024
e4dddcb
Update WinUIGallery/ControlPages/XamlFundamentals/XamlStylesPage.xaml
Zakariathr22 Nov 30, 2024
67ca607
chore: remove localizers from documentations URLs
Zakariathr22 Nov 30, 2024
504798e
fix: modify RichTextBoxes to prevent extra spaces and other small cha…
Zakariathr22 Nov 30, 2024
d5025bb
Update WinUIGallery/ControlPages/XamlFundamentals/BindingPage.xaml
Zakariathr22 Dec 1, 2024
b75a1f3
Update WinUIGallery/ControlPages/XamlFundamentals/BindingPage.xaml
Zakariathr22 Dec 1, 2024
b3ac8a6
Update WinUIGallery/ControlPages/XamlFundamentals/BindingPage.xaml
Zakariathr22 Dec 1, 2024
b980c38
Update WinUIGallery/ControlPages/XamlFundamentals/ResourceDictionaryP…
Zakariathr22 Dec 1, 2024
5b7b052
Update WinUIGallery/ControlPages/XamlFundamentals/ResourceDictionaryP…
Zakariathr22 Dec 1, 2024
46e799d
Update WinUIGallery/ControlPages/XamlFundamentals/ResourcesPage.xaml
Zakariathr22 Dec 1, 2024
5abd207
chore: replace bold with semi bold, bullets with dashes, and make oth…
Zakariathr22 Dec 1, 2024
9eab42d
Changes from Jay
Jay-o-Way Dec 2, 2024
81ac391
Changes from Jay
Jay-o-Way Dec 2, 2024
da8e477
Changes from Jay 2
Jay-o-Way Dec 2, 2024
7146314
Update LayoutSelector_SelectionChanged Method
Zakariathr22 Dec 2, 2024
5a1f27a
another change to LayoutSelector_SelectionChanged
Zakariathr22 Dec 2, 2024
00d3c5a
Update LayoutSelector_SelectionChanged Method
Zakariathr22 Dec 2, 2024
f8e3a35
improve table in Binding page
Jay-o-Way Dec 2, 2024
8f944d4
Merge branch 'XAML-Fundamentals' of https://github.com/Zakariathr22/W…
Jay-o-Way Dec 2, 2024
83cee34
remove obsolete resources
Jay-o-Way Dec 2, 2024
778f4d6
Merge branch 'XAML-Fundamentals' of https://github.com/Zakariathr22/W…
Zakariathr22 Dec 3, 2024
6bf1951
Updating binding examples
Zakariathr22 Dec 3, 2024
ccd127c
Minor adjustments
Jay-o-Way Dec 3, 2024
a289fd1
revert unrelated files
Jay-o-Way Dec 6, 2024
de567ae
add DefaultButtonStyle to fix hover fontcolor
Jay-o-Way Dec 6, 2024
b4681a0
Merge branch 'main' into XAML-Fundamentals
Jay-o-Way Dec 6, 2024
dd3b7a5
Merge branch 'XAML-Fundamentals' of https://github.com/Zakariathr22/W…
Jay-o-Way Dec 6, 2024
4ffc095
fix: update "binding" sample code text files to set build action as c…
Zakariathr22 Dec 6, 2024
e74ab01
Update: Combine the pages for Resources, ResourceDictionary, and Them…
Zakariathr22 Dec 6, 2024
a59958e
Update: Remove expanders from the Binding, Templates, and Styles pages.
Zakariathr22 Dec 6, 2024
545ca0f
refactor: update subtitles in XamlResources page
Zakariathr22 Dec 7, 2024
8f9d216
refactor: update subtitles in XamlResources page
Zakariathr22 Dec 7, 2024
033854a
Simplifiy Grid in XamlResourcesSample4 one step
Jay-o-Way Dec 7, 2024
a90f7d2
Merge branch 'XAML-Fundamentals' of https://github.com/Zakariathr22/W…
Jay-o-Way Dec 7, 2024
393a5e1
Update WinUIGallery/ControlPages/XamlFundamentals/TemplatesPage.xaml
Zakariathr22 Dec 8, 2024
1aa374a
Update WinUIGallery/Navigation/NavigationRootPage.xaml
Zakariathr22 Dec 8, 2024
f165c83
Update WinUIGallery/Navigation/NavigationRootPage.xaml
Zakariathr22 Dec 8, 2024
4b71cd0
Update text content in Resources and Templates pages
Zakariathr22 Dec 10, 2024
b35bd4e
Modify text content in Styles page and remove the 'Using Style in C#'…
Zakariathr22 Dec 10, 2024
548763e
Update text content in Binding page and remove the {x:Bind} vs {Bindi…
Zakariathr22 Dec 10, 2024
20539d7
Update code tag icon
Zakariathr22 Dec 10, 2024
d121986
Update WinUIGallery/Navigation/NavigationRootPage.xaml
Zakariathr22 Dec 10, 2024
4bbd838
Update WinUIGallery/ControlPages/XamlFundamentals/BindingPage.xaml
Zakariathr22 Dec 10, 2024
37d4d0c
Update WinUIGallery/ControlPages/XamlFundamentals/BindingPage.xaml
Zakariathr22 Dec 10, 2024
db6d443
Update WinUIGallery/ControlPages/XamlFundamentals/XamlStylesPage.xaml
Zakariathr22 Dec 10, 2024
037a045
Remove the redundant header from the Templates page
Zakariathr22 Dec 10, 2024
c2f1349
Rearrange the control examples on the Templates page
Zakariathr22 Dec 10, 2024
895211d
Update code tag icon
Zakariathr22 Dec 10, 2024
7fc60df
remove the unnecessary header from resouces page
Zakariathr22 Dec 10, 2024
5e0b8a0
Merge branch 'main' into XAML-Fundamentals
Zakariathr22 Dec 11, 2024
e987650
Merge branch 'microsoft:main' into XAML-Fundamentals
Zakariathr22 Dec 15, 2024
8c0a441
Tweaks
niels9001 Dec 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
niels9001 marked this conversation as resolved.
Show resolved Hide resolved
Zakariathr22 marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WinUIGallery/Assets/SampleMedia/Dark_Image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WinUIGallery/Assets/SampleMedia/Light_Image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
459 changes: 459 additions & 0 deletions WinUIGallery/ControlPages/XamlFundamentals/BindingPage.xaml

Large diffs are not rendered by default.

173 changes: 173 additions & 0 deletions WinUIGallery/ControlPages/XamlFundamentals/BindingPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Microsoft.UI.Xaml.Documents;
using System.ComponentModel;

namespace WinUIGallery.ControlPages
{
public sealed partial class BindingPage : Page
{
public ExampleViewModel ViewModel { get; set; }

public BindingPage()
{
this.InitializeComponent();

ViewModel = new ExampleViewModel
{
Title = "Welcome to WinUI 3",
Description = "This is an example of binding to a view model.",
NullString = null
};
DataContext = ViewModel;

mvvmToolkitSampleAppHyperlinkButton.NavigateUri = new Uri("https://github.com/CommunityToolkit/MVVM-Samples");
}

private void BindingModeGroup_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (sender is RadioButtons radioButtons)
{
switch (radioButtons.SelectedIndex)
{
case 0:
UpdateBindingAndDescription(BindingMode.OneWay);
break;
case 1:
UpdateBindingAndDescription(BindingMode.TwoWay);
break;
}
}
}

private void UpdateBindingAndDescription(BindingMode bindingMode)
{
var binding = new Binding
{
Source = SourceTextBox,
Path = new PropertyPath("Text"),
Mode = bindingMode,
};
TargetTextBox.SetBinding(TextBox.TextProperty, binding);

BindingModeDescription.Blocks.Clear();
var paragraph = new Paragraph();
if (bindingMode == BindingMode.OneWay)
{
paragraph.Inlines.Add(new Run
{
Text = "In ",
});
paragraph.Inlines.Add(new Bold { Inlines = { new Run { Text = "OneWay" } } });
paragraph.Inlines.Add(new Run
{
Text = " binding mode, changes in the source (`SourceTextBox`) are reflected in the target, but not vice versa."
});
}
else if (bindingMode == BindingMode.TwoWay)
{
paragraph.Inlines.Add(new Run
{
Text = "In ",
});
paragraph.Inlines.Add(new Bold { Inlines = { new Run { Text = "TwoWay" } } });
paragraph.Inlines.Add(new Run
{
Text = " binding mode, changes in either box update the other."
});
}

BindingModeDescription.Blocks.Add(paragraph);
}

public string FormatDate(DateTimeOffset? date)
{
if (date.HasValue)
{
return "Selected date is: " + date.Value.ToString("dddd, MMMM d, yyyy");
}
else
{
return "No date selected";
}
}
}

public class ExampleViewModel : INotifyPropertyChanged
{
private string _title;
private string _description;
private string _nullString;

public string Title
{
get => _title;
set
{
if (_title != value)
{
_title = value;
OnPropertyChanged(nameof(Title));
}
}
}

public string Description
{
get => _description;
set
{
if (_description != value)
{
_description = value;
OnPropertyChanged(nameof(Description));
}
}
}

public string NullString
{
get => _nullString;
set
{
if (_nullString != value)
{
_nullString = value;
OnPropertyChanged(nameof(_nullString));
}
}
}

public event PropertyChangedEventHandler PropertyChanged;

protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}

public class BooleanToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return (bool)value ? Visibility.Visible : Visibility.Collapsed;
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
return (Visibility)value == Visibility.Visible;
}
}
}
163 changes: 163 additions & 0 deletions WinUIGallery/ControlPages/XamlFundamentals/ResourceDictionaryPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<?xml version="1.0" encoding="utf-8"?>
<Page x:Class="WinUIGallery.ControlPages.ResourceDictionaryPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WinUIGallery"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Page.Resources>
<ResourceDictionary>
<x:Double x:Key="HeaderFontSize">24</x:Double>
<Color x:Key="AccentColor">#4CAF50</Color>
<SolidColorBrush x:Key="AccentBrush"
Color="{StaticResource AccentColor}" />
<x:String x:Key="AppTitle">WinUI 3 Gallery</x:String>

<x:String x:Key="WelcomeMessage">Welcome to this page</x:String>
<SolidColorBrush x:Key="PageBackgroundBrush"
Color="#E8EAF6" />
Zakariathr22 marked this conversation as resolved.
Show resolved Hide resolved

<Color x:Key="SecondaryColor">#2196F3</Color>
<SolidColorBrush x:Key="SecondaryBrush"
Color="{StaticResource SecondaryColor}" />
</ResourceDictionary>
</Page.Resources>

<StackPanel>
<Expander HorizontalAlignment="Stretch"
HorizontalContentAlignment="Left"
Margin="0 12 0 0">
<Expander.Header>
<TextBlock Text="Understanding and using resource dictionaries in WinUI 3"
Margin="0 24" />
</Expander.Header>
<StackPanel>
<RichTextBlock Margin="0 0 0 12">
<Paragraph>
<Run Text="Where can you create a resource dictionary?"
FontWeight="Bold" />
</Paragraph>
<Paragraph>
<Run Text="1."
FontWeight="Bold" />
<Run Text="Inline (app-level):"
FontWeight="Bold" />
<Run Text="define it in" />
<Run Text="App.xaml"
FontFamily="Consolas"
FontWeight="Bold" />
<Run Text=" to make resources globally available across the entire app." />
Zakariathr22 marked this conversation as resolved.
Show resolved Hide resolved
</Paragraph>
<Paragraph>
<Run Text="2."
FontWeight="Bold" />
<Run Text="Inline (page-level):"
FontWeight="Bold" />
<Run Text="define it in a specific page to limit the scope to that page." />
</Paragraph>
<Paragraph>
<Run Text="3."
FontWeight="Bold" />
<Run Text="Standalone file:"
FontWeight="Bold" />
<Run Text="define it in a separate" />
<Run Text=".xaml"
FontFamily="Consolas"
FontWeight="Bold" />
<Run Text=" file to organize resources and reuse them in different parts of your app." />
Zakariathr22 marked this conversation as resolved.
Show resolved Hide resolved
</Paragraph>
</RichTextBlock>

<RichTextBlock>
<Paragraph>
<Run Text="Why use resource dictionaries?"
FontWeight="Bold" />
</Paragraph>
<Paragraph>
<Run Text="1. "
FontWeight="Bold" />
<Run Text="Reusability: "
FontWeight="Bold" />
<Run Text="define once and use many times." />
</Paragraph>
<Paragraph>
<Run Text="2. "
FontWeight="Bold" />
<Run Text="Organization: "
FontWeight="Bold" />
<Run Text="keeps resources modular and separated." />
</Paragraph>
<Paragraph>
<Run Text="3. "
FontWeight="Bold" />
<Run Text="Maintainability: "
FontWeight="Bold" />
<Run Text="makes it easier to update values across the app." />
</Paragraph>
</RichTextBlock>
</StackPanel>
</Expander>

<local:ControlExample HeaderText="Define and use ResourceDictionary inline in App.xaml"
XamlSource="ResourceDictionary\ResourceDictionarySample1_xaml.txt">
<local:ControlExample.Example>
<Grid Background="{StaticResource AccentBrush}">
<StackPanel HorizontalAlignment="Center"
VerticalAlignment="Center">
<TextBlock Text="{StaticResource AppTitle}"
FontSize="{StaticResource HeaderFontSize}"
Foreground="White" />
</StackPanel>
</Grid>
</local:ControlExample.Example>
<local:ControlExample.CSharp>
<x:String xml:space="preserve">
//YourPage.xaml.cs

//You can retrieve resources defined at the ResourceDictionary like this
var appTitle = (string)Application.Current.Resources["AppTitle"];
var headerFontSize = (double)Application.Current.Resources["HeaderFontSize"];
</x:String>
</local:ControlExample.CSharp>
</local:ControlExample>

<local:ControlExample HeaderText="Define page-level ResourceDictionary"
XamlSource="ResourceDictionary\ResourceDictionarySample2_xaml.txt">
<local:ControlExample.Example>
<Grid Background="{StaticResource PageBackgroundBrush}">
<TextBlock Text="{StaticResource WelcomeMessage}"
FontSize="20"
Foreground="Black" />
</Grid>
</local:ControlExample.Example>
<local:ControlExample.CSharp>
<x:String xml:space="preserve">
//YourPage.xaml.cs

//You can retrieve the resource defined at the ResourceDictionary like this
var welcomeMessage = (string)this.Resources["WelcomeMessage"];
</x:String>
</local:ControlExample.CSharp>
</local:ControlExample>

<local:ControlExample HeaderText="Define a separate ResourceDictionary file by adding a new .xaml file (e.g., Colors.xaml) to the project"
XamlSource="ResourceDictionary\ResourceDictionarySample3_xaml.txt">
<local:ControlExample.Example>
<Grid Background="{StaticResource SecondaryBrush}">
<TextBlock Text="Using colors from ResourceDictionary"
Foreground="White" />
</Grid>
</local:ControlExample.Example>
<local:ControlExample.CSharp>
<x:String xml:space="preserve">
//YourPage.xaml.cs

//You can retrieve the resource defined at the ResourceDictionary like this
var secondaryBrush = (SolidColorBrush)Application.Current.Resources["SecondaryBrush"];
</x:String>
</local:ControlExample.CSharp>
</local:ControlExample>
</StackPanel>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Windows.Foundation;
using Windows.Foundation.Collections;

namespace WinUIGallery.ControlPages
{
public sealed partial class ResourceDictionaryPage : Page
{
public ResourceDictionaryPage()
{
this.InitializeComponent();
}
}
}
Loading