-
Notifications
You must be signed in to change notification settings - Fork 721
feat: Add XAML Fundamentals section with pages and examples #1661
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
Merged
Merged
Changes from all commits
Commits
Show all changes
82 commits
Select commit
Hold shift + click to select a range
01009d7
**feat**: Add XAML Fundamentals section with pages, examples, assets,…
Zakariathr22 0343c59
Update BindingPage: Refactor some examples to use x:Bind, add x:Bind …
Zakariathr22 54d2944
Update some examples and their sample code for improved clarity and u…
Zakariathr22 014506c
feat: Improve "x:Bind and Binding differences table" in `BindingPage.…
Zakariathr22 b916465
fix: correct unnecessary capitalization
Zakariathr22 7cfce1f
Update navigation symbol in InfoBar message on ThemeResourcesPage
Zakariathr22 85aab8a
feat: enhance BindingPage with new examples, design improvements, and…
Zakariathr22 dafd023
feat: add BasedOn property example and improve design in XamlStylesPage
Zakariathr22 fbcd5af
chore: minor design tweaks for TemplatesPage and ThemeResourcesPage
Zakariathr22 a96c434
chore: update x:Bind vs Binding table and add documentation links
Zakariathr22 a2a2c02
fix: update example header in BindingPage to replace `Converter` with…
Zakariathr22 381ab05
chore: remove unnecessary italics in XamlStylesPage
Zakariathr22 e4dddcb
Update WinUIGallery/ControlPages/XamlFundamentals/XamlStylesPage.xaml
Zakariathr22 67ca607
chore: remove localizers from documentations URLs
Zakariathr22 504798e
fix: modify RichTextBoxes to prevent extra spaces and other small cha…
Zakariathr22 d5025bb
Update WinUIGallery/ControlPages/XamlFundamentals/BindingPage.xaml
Zakariathr22 b75a1f3
Update WinUIGallery/ControlPages/XamlFundamentals/BindingPage.xaml
Zakariathr22 b3ac8a6
Update WinUIGallery/ControlPages/XamlFundamentals/BindingPage.xaml
Zakariathr22 b980c38
Update WinUIGallery/ControlPages/XamlFundamentals/ResourceDictionaryP…
Zakariathr22 5b7b052
Update WinUIGallery/ControlPages/XamlFundamentals/ResourceDictionaryP…
Zakariathr22 46e799d
Update WinUIGallery/ControlPages/XamlFundamentals/ResourcesPage.xaml
Zakariathr22 5abd207
chore: replace bold with semi bold, bullets with dashes, and make oth…
Zakariathr22 9eab42d
Changes from Jay
Jay-o-Way 81ac391
Changes from Jay
Jay-o-Way da8e477
Changes from Jay 2
Jay-o-Way 7146314
Update LayoutSelector_SelectionChanged Method
Zakariathr22 5a1f27a
another change to LayoutSelector_SelectionChanged
Zakariathr22 00d3c5a
Update LayoutSelector_SelectionChanged Method
Zakariathr22 f8e3a35
improve table in Binding page
Jay-o-Way 8f944d4
Merge branch 'XAML-Fundamentals' of https://github.com/Zakariathr22/W…
Jay-o-Way 83cee34
remove obsolete resources
Jay-o-Way 778f4d6
Merge branch 'XAML-Fundamentals' of https://github.com/Zakariathr22/W…
Zakariathr22 6bf1951
Updating binding examples
Zakariathr22 ccd127c
Minor adjustments
Jay-o-Way a289fd1
revert unrelated files
Jay-o-Way de567ae
add DefaultButtonStyle to fix hover fontcolor
Jay-o-Way b4681a0
Merge branch 'main' into XAML-Fundamentals
Jay-o-Way dd3b7a5
Merge branch 'XAML-Fundamentals' of https://github.com/Zakariathr22/W…
Jay-o-Way 4ffc095
fix: update "binding" sample code text files to set build action as c…
Zakariathr22 e74ab01
Update: Combine the pages for Resources, ResourceDictionary, and Them…
Zakariathr22 a59958e
Update: Remove expanders from the Binding, Templates, and Styles pages.
Zakariathr22 545ca0f
refactor: update subtitles in XamlResources page
Zakariathr22 8f9d216
refactor: update subtitles in XamlResources page
Zakariathr22 033854a
Simplifiy Grid in XamlResourcesSample4 one step
Jay-o-Way a90f7d2
Merge branch 'XAML-Fundamentals' of https://github.com/Zakariathr22/W…
Jay-o-Way 393a5e1
Update WinUIGallery/ControlPages/XamlFundamentals/TemplatesPage.xaml
Zakariathr22 1aa374a
Update WinUIGallery/Navigation/NavigationRootPage.xaml
Zakariathr22 f165c83
Update WinUIGallery/Navigation/NavigationRootPage.xaml
Zakariathr22 4b71cd0
Update text content in Resources and Templates pages
Zakariathr22 b35bd4e
Modify text content in Styles page and remove the 'Using Style in C#'…
Zakariathr22 548763e
Update text content in Binding page and remove the {x:Bind} vs {Bindi…
Zakariathr22 20539d7
Update code tag icon
Zakariathr22 d121986
Update WinUIGallery/Navigation/NavigationRootPage.xaml
Zakariathr22 4bbd838
Update WinUIGallery/ControlPages/XamlFundamentals/BindingPage.xaml
Zakariathr22 37d4d0c
Update WinUIGallery/ControlPages/XamlFundamentals/BindingPage.xaml
Zakariathr22 db6d443
Update WinUIGallery/ControlPages/XamlFundamentals/XamlStylesPage.xaml
Zakariathr22 037a045
Remove the redundant header from the Templates page
Zakariathr22 c2f1349
Rearrange the control examples on the Templates page
Zakariathr22 895211d
Update code tag icon
Zakariathr22 7fc60df
remove the unnecessary header from resouces page
Zakariathr22 5e0b8a0
Merge branch 'main' into XAML-Fundamentals
Zakariathr22 e987650
Merge branch 'microsoft:main' into XAML-Fundamentals
Zakariathr22 8c0a441
Tweaks
niels9001 ec54570
Update the 'using a converter in binding' example
Zakariathr22 080b6db
update the 'creating and applying a style' example
Zakariathr22 11e00a4
Update xaml resources first example
Zakariathr22 a2f3f85
update the first example in the binding section
Zakariathr22 a962b21
remove api namespace and base classes from the resources and binding …
Zakariathr22 a1c2506
Tweaks
Zakariathr22 e9afa27
Merge branch 'microsoft:main' into XAML-Fundamentals
Zakariathr22 45a7a24
Tweaks
Zakariathr22 39e9223
Merge branch 'XAML-Fundamentals' of https://github.com/Zakariathr22/W…
Zakariathr22 af67c1d
add comments explaining one-way and two-way binding in xaml sample code
Zakariathr22 6e946d1
update the first example to use 'BasedOn' and remove the separate 'Ba…
Zakariathr22 fb1dfb8
Merge branch 'main' into XAML-Fundamentals
Zakariathr22 daed518
Remove resource dictionary part
Zakariathr22 924b010
Merge branch 'main' into XAML-Fundamentals
Zakariathr22 11fe9e6
Add "XAML fundamentals" to expected groups in unit test for ControlIn…
Zakariathr22 ff51e20
Update code tag icon for improved visualization
Zakariathr22 42c7ee0
remove unnecessary heading
Zakariathr22 44863f1
Refactor to use file-scoped namespace and remove unused namespaces
Zakariathr22 13bd9c1
Merge branch 'microsoft:main' into XAML-Fundamentals
Zakariathr22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
226 changes: 226 additions & 0 deletions
226
WinUIGallery/ControlPages/XamlFundamentals/BindingPage.xaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,226 @@ | ||
| <?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:c="using:WinUIGallery.Common" | ||
| xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
| mc:Ignorable="d"> | ||
|
|
||
| <Page.Resources> | ||
| <c:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter" /> | ||
| </Page.Resources> | ||
|
|
||
| <StackPanel> | ||
| <StackPanel Spacing="12" | ||
| Margin="0,12,0,0"> | ||
| <RichTextBlock> | ||
| <Paragraph FontWeight="SemiBold">Key concepts:</Paragraph> | ||
| <Paragraph>• Target: The property of a control to which data is bound (e.g., Text, Background, Visibility).</Paragraph> | ||
| <Paragraph>• Source: The data being bound, such as a property in a class, another control, or a static resource.</Paragraph> | ||
| <Paragraph>• 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> | ||
| <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" | ||
| XamlSource="Binding\BindingSample1_xaml.txt"> | ||
| <core:ControlExample.Example> | ||
| <StackPanel Spacing="12"> | ||
| <Grid ColumnSpacing="12"> | ||
| <Grid.ColumnDefinitions> | ||
| <ColumnDefinition Width="auto" /> | ||
| <ColumnDefinition Width="auto" /> | ||
| <ColumnDefinition Width="auto" /> | ||
| </Grid.ColumnDefinitions> | ||
|
|
||
| <StackPanel Spacing="8" | ||
| Grid.Column="0"> | ||
| <TextBlock Text="OneWay binding" | ||
| FontWeight="SemiBold" /> | ||
| <TextBox x:Name="SourceTextBoxOneWay" | ||
| Width="200" | ||
| HorizontalAlignment="Left" | ||
| PlaceholderText="Enter text here" /> | ||
| <TextBox x:Name="TargetTextBoxOneWay" | ||
| Width="200" | ||
| HorizontalAlignment="Left" | ||
| PlaceholderText="Mirrors above text" | ||
| Text="{x:Bind SourceTextBoxOneWay.Text, Mode=OneWay}" /> | ||
| </StackPanel> | ||
|
|
||
| <AppBarSeparator Grid.Column="1" /> | ||
|
|
||
| <StackPanel Spacing="8" | ||
| Grid.Column="2"> | ||
| <TextBlock Text="TwoWay binding" | ||
| FontWeight="SemiBold" /> | ||
| <TextBox x:Name="SourceTextBoxTwoWay" | ||
| Width="200" | ||
| HorizontalAlignment="Left" | ||
| PlaceholderText="Enter text here" /> | ||
| <TextBox x:Name="TargetTextBoxTwoWay" | ||
| Width="200" | ||
| HorizontalAlignment="Left" | ||
| PlaceholderText="Mirrors and edits above text" | ||
| Text="{x:Bind SourceTextBoxTwoWay.Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /> | ||
| </StackPanel> | ||
| </Grid> | ||
| <RichTextBlock> | ||
| <Paragraph> | ||
| <Run Text="In" /> | ||
| <Run Text="OneWay" | ||
| FontWeight="Semibold" /> | ||
| <Run Text="binding mode, changes in the source (SourceTextBox) are reflected in the target, but not vice versa." /> | ||
| </Paragraph> | ||
| <Paragraph> | ||
| <Run Text="In" /> | ||
| <Run Text="TwoWay" | ||
| FontWeight="Semibold" /> | ||
| <Run Text="binding mode, changes in either box update the other." /> | ||
| </Paragraph> | ||
| </RichTextBlock> | ||
| </StackPanel> | ||
| </core:ControlExample.Example> | ||
| </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"> | ||
| <TextBlock | ||
| Text="{x:Bind GreetingMessage}" | ||
| FontSize="24" | ||
| HorizontalAlignment="Center" | ||
| VerticalAlignment="Center" /> | ||
| </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}" /> | ||
| </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 Spacing="8"> | ||
| <TextBox x:Name="InputTextBox" Header="Enter Text:" Width="300" /> | ||
|
|
||
| <TextBlock Text="The input is not empty." | ||
| Visibility="{Binding Text, ElementName=InputTextBox, Converter={StaticResource EmptyStringToVisibilityConverter}}" /> | ||
| </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"> | ||
| <TextBlock Text="Title:" FontWeight="SemiBold" /> | ||
| <TextBlock Text="{Binding Title}" FontSize="16" /> | ||
|
|
||
| <TextBlock Text="Description:" FontWeight="SemiBold" /> | ||
| <TextBlock Text="{Binding Description}" FontSize="16" /> | ||
| </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"> | ||
| <!--FallbackValue and TargetNullValue properties help handle scenarios where the binding source is missing or null--> | ||
| <TextBlock Text="{Binding NonExistentProperty, FallbackValue='Default Text'}" /> | ||
| <TextBlock Text="{Binding NullString, TargetNullValue='Anonymous User'}" /> | ||
| </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> | ||
90 changes: 90 additions & 0 deletions
90
WinUIGallery/ControlPages/XamlFundamentals/BindingPage.xaml.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| using System; | ||
| using Microsoft.UI.Xaml.Controls; | ||
| using System.ComponentModel; | ||
|
|
||
| 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; | ||
| } | ||
|
|
||
| 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)); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.