-
Notifications
You must be signed in to change notification settings - Fork 751
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19239 from unoplatform/dev/xygu/20250114/contentc…
…ontrol-binding-cs1029 fix(codegen): ContentPresenter.Content binding compilation error
- Loading branch information
Showing
10 changed files
with
564 additions
and
35 deletions.
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
55 changes: 55 additions & 0 deletions
55
src/SourceGenerators/XamlGenerationTests/ContentPresenter_ContentBinding.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,55 @@ | ||
<Page x:Class="XamlGenerationTests.ContentPresenter_ContentBinding" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:XamlGenerationTests" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:void="There is no mistake so great that it cannot be undone." | ||
mc:Ignorable="d void"> | ||
<Page.Resources> | ||
|
||
<!-- OK: should work; unaffected in uno --> | ||
<DataTemplate x:Key="DTCPCB_DataTemplate"> | ||
<ContentPresenter Content="{Binding}" /> | ||
</DataTemplate> | ||
|
||
<!-- OK: should work; unaffected in uno --> | ||
<ControlTemplate x:Key="DTCPCB_UntypedCtrlTemplate_BindingBlank"> | ||
<ContentPresenter Content="{Binding}" /> | ||
</ControlTemplate> | ||
<ControlTemplate x:Key="DTCPCB_UntypedCtrlTemplate_BindingDot"> | ||
<ContentPresenter Content="{Binding .}" /> | ||
</ControlTemplate> | ||
<ControlTemplate x:Key="DTCPCB_ContentCtrlTemplate" TargetType="ContentControl"> | ||
<ContentPresenter Content="{Binding}" /> | ||
</ControlTemplate> | ||
<ControlTemplate x:Key="DTCPCB_DerivedContentCtrlTemplate" TargetType="Button"> | ||
<ContentPresenter Content="{Binding}" /> | ||
</ControlTemplate> | ||
<ControlTemplate x:Key="DTCPCB_NonContentCtrlTemplate" TargetType="TextBox"> | ||
<ContentPresenter Content="{Binding}" /> | ||
</ControlTemplate> | ||
|
||
<!-- OK: ControlTemplate\ContentPresenter.Content with Path works --> | ||
<ControlTemplate x:Key="DTCPCB_DerivedContentCtrlTemplate_SomePath_1" TargetType="Button"> | ||
<ContentPresenter Content="{Binding SomePath}" /> | ||
</ControlTemplate> | ||
<ControlTemplate x:Key="DTCPCB_DerivedContentCtrlTemplate_SomePath_2" TargetType="Button"> | ||
<ContentPresenter Content="{Binding Mode=OneTime, Path=SomePath}" /> | ||
</ControlTemplate> | ||
|
||
<!-- FAIL: DataTemplate\ContentPresenter.Content with Path should work, but doesn't --> | ||
<!-- for now, it should not compile--> | ||
<void:DataTemplate x:Key="DTCPCB_ContentDataTemplate_SomePath"> | ||
<ContentPresenter Content="{Binding SomePath}" /> | ||
</void:DataTemplate> | ||
|
||
</Page.Resources> | ||
|
||
<StackPanel> | ||
<!-- OK: should work; unaffected in uno --> | ||
<ContentPresenter Content="{Binding}" /> | ||
<ContentPresenter Content="{Binding SomePath}" /> | ||
</StackPanel> | ||
|
||
</Page> |
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,64 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
|
||
namespace Uno.UI.RuntimeTests.Extensions; | ||
|
||
public static class StringExtensions | ||
{ | ||
/// <summary> | ||
/// Split a string by a separator, while ignoring certain regex pattern to be splitted. | ||
/// </summary> | ||
/// <param name="input"></param> | ||
/// <param name="separator"></param> | ||
/// <param name="ignoredPattern"></param> | ||
/// <param name="options"></param> | ||
/// <remarks>This is typically used to split separator-seperator string that contains brackets.</remarks> | ||
/// <returns></returns> | ||
public static string[] SplitWithIgnore(this string input, char separator, string ignoredPattern, StringSplitOptions options = StringSplitOptions.None) | ||
{ | ||
var ignores = Regex.Matches(input, ignoredPattern); | ||
|
||
var shards = new List<string>(); | ||
for (int i = 0; i < input.Length; i++) | ||
{ | ||
var nextSeparator = input.IndexOf(separator, i); | ||
|
||
// find the next separator, if we are within the ignored pattern | ||
while (nextSeparator != -1 && ignores.FirstOrDefault(x => InRange(x, nextSeparator)) is { } enclosingIgnore) | ||
{ | ||
nextSeparator = enclosingIgnore.Index + enclosingIgnore.Length is { } afterIgnore && afterIgnore < input.Length | ||
? input.IndexOf(separator, afterIgnore) | ||
: -1; | ||
} | ||
|
||
if (nextSeparator != -1) | ||
{ | ||
shards.Add(input.Substring(i, nextSeparator - i)); | ||
i = nextSeparator; | ||
|
||
// skip multiple continuous spaces | ||
while (options.HasFlag(StringSplitOptions.RemoveEmptyEntries) && i + 1 < input.Length && input[i + 1] == separator) i++; | ||
} | ||
else | ||
{ | ||
shards.Add(input.Substring(i)); | ||
break; | ||
} | ||
} | ||
|
||
if (options.HasFlag(StringSplitOptions.TrimEntries)) | ||
{ | ||
return shards.Select(x => x.Trim()).ToArray(); | ||
} | ||
else | ||
{ | ||
return shards.ToArray(); | ||
} | ||
|
||
bool InRange(Match x, int index) => x.Index <= index && index < (x.Index + x.Length); | ||
} | ||
} |
Oops, something went wrong.