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 45 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.
324 changes: 324 additions & 0 deletions WinUIGallery/ControlPages/XamlFundamentals/BindingPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,324 @@
<?xml version="1.0" encoding="utf-8" ?>
<Page x:Class="WinUIGallery.ControlPages.BindingPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:core="using:WinUIGallery"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:WinUIGallery.ControlPages"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<StackPanel>

<StackPanel Spacing="12"
Margin="0,12,0,0">
<RichTextBlock>
<Paragraph FontWeight="SemiBold">Key concepts:</Paragraph>
<Paragraph>1. Target: the property of a control that you want to bind to (e.g. Text, Background, Visibility).</Paragraph>
<Paragraph>2. Source: the data you are binding to, like a property in a class, another control, or a static resource.</Paragraph>
<Paragraph>3. Binding modes:</Paragraph>
<Paragraph xml:space="preserve"> - OneWay updates the target when the source changes.</Paragraph>
<Paragraph xml:space="preserve"> - TwoWay updates both the target and the source.</Paragraph>
<Paragraph xml:space="preserve"> - OneTime sets the target once and doesn't update afterward.</Paragraph>
</RichTextBlock>

<RichTextBlock>
<Paragraph FontWeight="SemiBold">{x:Bind} and {Binding} feature comparison</Paragraph>
Zakariathr22 marked this conversation as resolved.
Show resolved Hide resolved
<Paragraph>
<Run Text="The following table highlights a few differences between" />
<Run FontFamily="Consolas"
Text="x:Bind" />
<Run Text="and" />
<Run FontFamily="Consolas"
Text="Binding" /> .
<Run Text="Go to" />
<Hyperlink NavigateUri="https://learn.microsoft.com/windows/apps/develop/data-binding/data-binding-in-depth#xbind-and-binding-feature-comparison">Microsoft Learn</Hyperlink>
<Run Text="for a full list." />
</Paragraph>
</RichTextBlock>

<Grid Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
BorderThickness="1,1,1,0"
MaxWidth="1024"
HorizontalAlignment="Left">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="3*" />
</Grid.ColumnDefinitions>
<Grid.Resources>
<Style TargetType="Border">
<Setter Property="BorderBrush"
Value="{ThemeResource CardStrokeColorDefaultBrush}" />
<Setter Property="BorderThickness"
Value="0,0,0,1" />
</Style>
<Style TargetType="TextBlock">
<Setter Property="Padding"
Value="8" />
<Setter Property="TextWrapping"
Value="Wrap" />
</Style>
</Grid.Resources>

<!-- Header Row -->
<Border Grid.Row="0"
Grid.Column="0">
<TextBlock FontWeight="SemiBold"
Text="Binding kind" />
</Border>
<Border Grid.Row="0"
Grid.Column="1">
<TextBlock FontWeight="SemiBold"
Text="x:Bind" />
</Border>
<Border Grid.Row="0"
Grid.Column="2">
<TextBlock FontWeight="SemiBold"
Text="Binding" />
</Border>

<!-- Row 1 -->
<Border Grid.Row="1"
Grid.Column="0">
<TextBlock FontWeight="SemiBold"
Text="What it is"
Visibility="Collapsed" />
</Border>
<Border Grid.Row="1"
Grid.Column="1">
<TextBlock Text="A performance-optimized binding system with compile-time checks." />
</Border>
<Border Grid.Row="1"
Grid.Column="2">
<TextBlock Text="A flexible data-binding system for UI elements and data sources." />
</Border>

<!-- Row 2 -->
<Border Grid.Row="2"
Grid.Column="0">
<TextBlock FontWeight="SemiBold"
Text="Key features" />
</Border>
<Border Grid.Row="2"
Grid.Column="1">
<TextBlock Padding="8">
<TextBlock.Inlines>
<Run Text="- Faster" />
<LineBreak />
<Run Text="- Compile-time checked" />
<LineBreak />
<Run Text="- Simplified syntax (strongly typed)" />
</TextBlock.Inlines>
</TextBlock>
</Border>
<Border Grid.Row="2"
Grid.Column="2">
<TextBlock Padding="8">
<TextBlock.Inlines>
<Run Text="- Dynamic data" />
<LineBreak />
<Run Text="- Runtime-based, no compile-time checks" />
</TextBlock.Inlines>
</TextBlock>
</Border>

<!-- Row 3 -->
<Border Grid.Row="3"
Grid.Column="0">
<TextBlock FontWeight="SemiBold"
Text="Default data source" />
</Border>
<Border Grid.Row="3"
Grid.Column="1">
<TextBlock Text="Property bound directly from code-behind or controls, no DataContext required." />
</Border>
<Border Grid.Row="3"
Grid.Column="2">
<TextBlock Text="DataContext (or manually set ElementName, Source)." />
</Border>

<!-- Row 4 -->
<Border Grid.Row="4"
Grid.Column="0">
<TextBlock FontWeight="SemiBold"
Text="Default binding mode" />
</Border>
<Border Grid.Row="4"
Grid.Column="1">
<TextBlock Text="OneTime" />
</Border>
<Border Grid.Row="4"
Grid.Column="2">
<TextBlock Text="OneWay" />
</Border>
</Grid>
</StackPanel>

<core:ControlExample HeaderText="Binding between controls">
<core:ControlExample.Example>
<StackPanel Spacing="8">
<TextBox x:Name="SourceTextBox"
Width="200"
HorizontalAlignment="Left"
PlaceholderText="Enter text here" />
<TextBox x:Name="TargetTextBox"
Width="200"
HorizontalAlignment="Left"
PlaceholderText="Mirrors above text"
Text="{x:Bind SourceTextBox.Text, Mode=OneWay}" />
<RichTextBlock x:Name="BindingModeDescription" />
</StackPanel>
</core:ControlExample.Example>
<core:ControlExample.Xaml>
<x:String xml:space="preserve">
&lt;TextBox x:Name="SourceTextBox" Width="200" PlaceholderText="Enter text here" /&gt;
&lt;TextBox Width="200" Text="{x:Bind SourceTextBox.Text, Mode=$(BindingMode)}" PlaceholderText="Mirrors above text" /&gt;
</x:String>
</core:ControlExample.Xaml>
<core:ControlExample.Options>
<RadioButtons x:Name="BindingModeGroup"
Header="Select binding mode"
SelectedIndex="0"
SelectionChanged="BindingModeGroup_SelectionChanged">
<x:String>OneWay</x:String>
<x:String>TwoWay</x:String>
</RadioButtons>
</core:ControlExample.Options>
<core:ControlExample.Substitutions>
<core:ControlExampleSubstitution Key="BindingMode"
Value="{x:Bind BindingModeGroup.SelectedItem, Mode=OneWay}" />
</core:ControlExample.Substitutions>
</core:ControlExample>

<core:ControlExample HeaderText="Binding to a property in code-behind">
<core:ControlExample.Example>
<StackPanel Spacing="8">
<TextBlock Text="{x:Bind GreetingMessage}"
FontSize="24"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</StackPanel>
</core:ControlExample.Example>
<core:ControlExample.Xaml>
<x:String xml:space="preserve">
&lt;TextBlock
Text="{x:Bind GreetingMessage}"
FontSize="24"
HorizontalAlignment="Center"
VerticalAlignment="Center" /&gt;
</x:String>
</core:ControlExample.Xaml>
<core:ControlExample.CSharp>
<x:String xml:space="preserve">
// Code-behind
public string GreetingMessage { get; set; } = "Hello, WinUI 3!";
</x:String>
</core:ControlExample.CSharp>
</core:ControlExample>

<core:ControlExample HeaderText="Using a function in x:Bind"
CSharpSource="Binding\BindingSample3_csharp.txt"
XamlSource="Binding\BindingSample3_xaml.txt">
<core:ControlExample.Example>
<StackPanel Spacing="8">
<DatePicker x:Name="DatePickerControl"
Header="Select a date" />
<TextBlock Text="{x:Bind FormatDate(DatePickerControl.SelectedDate), Mode=OneWay}" />
Zakariathr22 marked this conversation as resolved.
Show resolved Hide resolved
</StackPanel>
</core:ControlExample.Example>
</core:ControlExample>

<core:ControlExample HeaderText="Using a converter in Binding"
CSharpSource="Binding\BindingSample4_csharp.txt"
XamlSource="Binding\BindingSample4_xaml.txt">
<core:ControlExample.Example>
<StackPanel>
<CheckBox x:Name="ToggleCheckBox"
Content="Show rectangle" />
<Rectangle Width="100"
Height="100"
Fill="{ThemeResource SystemFillColorAttentionBrush}"
Visibility="{Binding IsChecked, ElementName=ToggleCheckBox}" />
</StackPanel>
</core:ControlExample.Example>
</core:ControlExample>

<core:ControlExample HeaderText="Binding to a view model"
CSharpSource="Binding\BindingSample5_csharp.txt">
<core:ControlExample.Example>
<StackPanel Spacing="8">
<TextBlock FontWeight="SemiBold"
Text="Title:" />
<TextBlock FontSize="16"
Text="{Binding Title}" />

<TextBlock FontWeight="SemiBold"
Text="Description:" />
<TextBlock FontSize="16"
Text="{Binding Description}" />
</StackPanel>
</core:ControlExample.Example>
<core:ControlExample.Xaml>
<x:String xml:space="preserve">
&lt;TextBlock Text="Title:" FontWeight="SemiBold" /&gt;
&lt;TextBlock Text="{Binding Title}" FontSize="16" /&gt;

&lt;TextBlock Text="Description:" FontWeight="SemiBold" /&gt;
&lt;TextBlock Text="{Binding Description}" FontSize="16" /&gt;
</x:String>
</core:ControlExample.Xaml>
</core:ControlExample>
<InfoBar Title="MVVM Toolkit"
Margin="0,8,0,0"
IsClosable="False"
IsOpen="True"
Message="There is a library called the MVVM Toolkit, part of the Windows Community Toolkit, designed to simplify the implementation of the Model-View-ViewModel (MVVM) pattern in applications. The toolkit includes a sample app to demonstrate its features and usage."
Severity="Informational">
<InfoBar.ActionButton>
<HyperlinkButton x:Name="mvvmToolkitSampleAppHyperlinkButton"
Content="Go to the MVVM Toolkit repository"
NavigateUri="https://github.com/CommunityToolkit/MVVM-Samples" />
</InfoBar.ActionButton>
</InfoBar>

<core:ControlExample HeaderText="Binding with FallbackValue and TargetNullValue">
<core:ControlExample.Example>
<StackPanel Spacing="8">
<TextBlock Text="{Binding NonExistentProperty, FallbackValue='Default Text'}" />
<TextBlock Text="{Binding NullString, TargetNullValue='Anonymous User'}" />
</StackPanel>
</core:ControlExample.Example>
<core:ControlExample.Xaml>
<x:String xml:space="preserve">
&lt;!--FallbackValue and TargetNullValue properties help handle scenarios where the binding source is missing or null--&gt;
&lt;TextBlock Text="{Binding NonExistentProperty, FallbackValue='Default Text'}" /&gt;
&lt;TextBlock Text="{Binding NullString, TargetNullValue='Anonymous User'}" /&gt;
</x:String>
</core:ControlExample.Xaml>
<core:ControlExample.CSharp>
<x:String xml:space="preserve">
public YourPage()
{
this.InitializeComponent();

ViewModel = new ExampleViewModel
{
NullString = null
};

DataContext = ViewModel;
}
</x:String>
</core:ControlExample.CSharp>
</core:ControlExample>
</StackPanel>
</Page>
Loading