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 59 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
Binary file added WinUIGallery/Assets/ControlImages/CodeTagIcon.png
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.
199 changes: 199 additions & 0 deletions WinUIGallery/ControlPages/XamlFundamentals/BindingPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
<?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 to which data is bound (e.g., Text, Background, Visibility).</Paragraph>
<Paragraph>2. Source: The data being bound, such as 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 does not 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="Learn more about the differences between" />
<Run FontFamily="Consolas"
Text="x:Bind" />
<Run Text="and" />
<Run FontFamily="Consolas"
Text="Binding" />
<Run Text="by visiting" />
<Hyperlink NavigateUri="https://learn.microsoft.com/windows/apps/develop/data-binding/data-binding-in-depth#xbind-and-binding-feature-comparison">
Microsoft Learn
</Hyperlink>.
</Paragraph>
</RichTextBlock>
</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>
161 changes: 161 additions & 0 deletions WinUIGallery/ControlPages/XamlFundamentals/BindingPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
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;
using Microsoft.UI.Text;

namespace WinUIGallery.ControlPages
{
public sealed partial class BindingPage : Page
{
public string GreetingMessage { get; set; } = "Hello, WinUI 3!";

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;
}

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 Run { Text = "OneWay", FontWeight = FontWeights.SemiBold });
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 Run { Text = "TwoWay", FontWeight = FontWeights.SemiBold });
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 partial 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));
}
}
}
Loading