-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[XC] Compile TemplateBindingExtension #22008
Merged
rmarinho
merged 3 commits into
dotnet:net9.0
from
simonrozsival:compile-template-binding
May 29, 2024
Merged
Changes from all commits
Commits
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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
19 changes: 19 additions & 0 deletions
19
src/Controls/tests/Xaml.UnitTests/TemplateBindingsCompiler.xaml
This file contains 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,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ContentPage | ||
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:local="clr-namespace:Microsoft.Maui.Controls.Xaml.UnitTests" | ||
x:Class="Microsoft.Maui.Controls.Xaml.UnitTests.TemplateBindingsCompiler" > | ||
<ContentPage.Resources> | ||
<ControlTemplate x:Key="MyCardTemplate"> | ||
<Label | ||
x:Name="CardTitleLabel" | ||
Text="{TemplateBinding CardTitle, x:DataType=local:TemplateBindingCompilerTestCardView}" /> | ||
</ControlTemplate> | ||
</ContentPage.Resources> | ||
|
||
<local:TemplateBindingCompilerTestCardView | ||
x:Name="ContentView" | ||
CardTitle="The title" | ||
ControlTemplate="{StaticResource MyCardTemplate}" /> | ||
</ContentPage> |
61 changes: 61 additions & 0 deletions
61
src/Controls/tests/Xaml.UnitTests/TemplateBindingsCompiler.xaml.cs
This file contains 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,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Diagnostics; | ||
using System.Runtime.CompilerServices; | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.Controls.Core.UnitTests; | ||
using Microsoft.Maui.Controls.Internals; | ||
using Microsoft.Maui.Dispatching; | ||
using Microsoft.Maui.UnitTests; | ||
using NUnit.Framework; | ||
|
||
namespace Microsoft.Maui.Controls.Xaml.UnitTests | ||
{ | ||
public partial class TemplateBindingsCompiler : ContentPage | ||
{ | ||
public TemplateBindingsCompiler() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
public TemplateBindingsCompiler(bool useCompiledXaml) | ||
{ | ||
//this stub will be replaced at compile time | ||
} | ||
|
||
[TestFixture] | ||
public class Tests | ||
{ | ||
[SetUp] public void Setup() => DispatcherProvider.SetCurrent(new DispatcherProviderStub()); | ||
[TearDown] public void TearDown() => DispatcherProvider.SetCurrent(null); | ||
|
||
[TestCase(false)] | ||
[TestCase(true)] | ||
public void Test(bool useCompiledXaml) | ||
{ | ||
var page = new TemplateBindingsCompiler(useCompiledXaml); | ||
var label = (Label)page.ContentView.GetTemplateChild("CardTitleLabel"); | ||
Assert.AreEqual("The title", label?.Text); | ||
|
||
if (useCompiledXaml) | ||
{ | ||
var binding = label.GetContext(Label.TextProperty).Bindings.GetValue(); | ||
Assert.That(binding, Is.TypeOf<TypedBinding<TemplateBindingCompilerTestCardView, string>>()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public class TemplateBindingCompilerTestCardView : ContentView | ||
{ | ||
public static readonly BindableProperty CardTitleProperty = | ||
BindableProperty.Create(nameof(CardTitle), typeof(string), typeof(TemplateBindingCompilerTestCardView), string.Empty); | ||
|
||
public string CardTitle | ||
{ | ||
get => (string)GetValue(CardTitleProperty); | ||
set => SetValue(CardTitleProperty, value); | ||
} | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope we can remove this condition in #22023