-
Notifications
You must be signed in to change notification settings - Fork 691
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 15 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
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.
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.
459 changes: 459 additions & 0 deletions
459
WinUIGallery/ControlPages/XamlFundamentals/BindingPage.xaml
Large diffs are not rendered by default.
Oops, something went wrong.
173 changes: 173 additions & 0 deletions
173
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,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
163
WinUIGallery/ControlPages/XamlFundamentals/ResourceDictionaryPage.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,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> |
25 changes: 25 additions & 0 deletions
25
WinUIGallery/ControlPages/XamlFundamentals/ResourceDictionaryPage.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,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(); | ||
} | ||
} | ||
} |
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.