diff --git a/eng/devices/catalyst.cake b/eng/devices/catalyst.cake index 5fe0fb1a2a2b..a9d44c324a72 100644 --- a/eng/devices/catalyst.cake +++ b/eng/devices/catalyst.cake @@ -173,7 +173,6 @@ void ExecuteBuildUITestApp(string appProject, string binDir, string config, stri Framework = tfm, ToolPath = toolPath, ArgumentCustomization = args => args - .Append("/t:Restore;Build") .Append($"/bl:{binlog}") }); diff --git a/src/Compatibility/Core/src/Android/Renderers/ListViewAdapter.cs b/src/Compatibility/Core/src/Android/Renderers/ListViewAdapter.cs index 844caa2f622d..8336909f2134 100644 --- a/src/Compatibility/Core/src/Android/Renderers/ListViewAdapter.cs +++ b/src/Compatibility/Core/src/Android/Renderers/ListViewAdapter.cs @@ -738,7 +738,7 @@ Cell GetNewGroupHeaderCell(ITemplatedItemsList group) groupHeaderCell = new TextCell(); groupHeaderCell.SetBinding( TextCell.TextProperty, - TypedBinding.ForSingleNestingLevel(nameof(group.Name), static (ITemplatedItemsList g) => g.Name)); + static (ITemplatedItemsList g) => g.Name); groupHeaderCell.BindingContext = group; } diff --git a/src/Compatibility/Core/src/Compatibility.csproj b/src/Compatibility/Core/src/Compatibility.csproj index 23b3529955a2..56cf3d239ba8 100644 --- a/src/Compatibility/Core/src/Compatibility.csproj +++ b/src/Compatibility/Core/src/Compatibility.csproj @@ -52,6 +52,18 @@ + + $(InterceptorsPreviewNamespaces);Microsoft.Maui.Controls.Generated + + $(CompilerResponseFile);WorkaroundXamlPreCompilePreviewFeatures.rsp + + + + + diff --git a/src/Compatibility/Core/src/WorkaroundXamlPreCompilePreviewFeatures.rsp b/src/Compatibility/Core/src/WorkaroundXamlPreCompilePreviewFeatures.rsp new file mode 100644 index 000000000000..e60a129bbc68 --- /dev/null +++ b/src/Compatibility/Core/src/WorkaroundXamlPreCompilePreviewFeatures.rsp @@ -0,0 +1 @@ +/features:"InterceptorsPreviewNamespaces=Microsoft.Maui.Controls.Generated" \ No newline at end of file diff --git a/src/Controls/src/BindingSourceGen/BindingCodeWriter.cs b/src/Controls/src/BindingSourceGen/BindingCodeWriter.cs index 360a4e14743e..3548b19d7a4c 100644 --- a/src/Controls/src/BindingSourceGen/BindingCodeWriter.cs +++ b/src/Controls/src/BindingSourceGen/BindingCodeWriter.cs @@ -18,28 +18,6 @@ public static string GenerateCommonCode() => $$""" //------------------------------------------------------------------------------ #nullable enable - namespace System.Runtime.CompilerServices - { - using System; - using System.CodeDom.Compiler; - - {{GeneratedCodeAttribute}} - [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] - internal sealed class InterceptsLocationAttribute : Attribute - { - public InterceptsLocationAttribute(string filePath, int line, int column) - { - FilePath = filePath; - Line = line; - Column = column; - } - - public string FilePath { get; } - public int Line { get; } - public int Column { get; } - } - } - namespace Microsoft.Maui.Controls.Generated { using System.CodeDom.Compiler; @@ -73,6 +51,28 @@ private static string GenerateBindingCode(string bindingMethodBody) => $$""" //------------------------------------------------------------------------------ #nullable enable + namespace System.Runtime.CompilerServices + { + using System; + using System.CodeDom.Compiler; + + {{GeneratedCodeAttribute}} + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + file sealed class InterceptsLocationAttribute : Attribute + { + public InterceptsLocationAttribute(string filePath, int line, int column) + { + FilePath = filePath; + Line = line; + Column = column; + } + + public string FilePath { get; } + public int Line { get; } + public int Column { get; } + } + } + namespace Microsoft.Maui.Controls.Generated { using System; diff --git a/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewAdapter.cs b/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewAdapter.cs index 92647b2b075b..630a352ac9ff 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewAdapter.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewAdapter.cs @@ -763,9 +763,7 @@ Cell GetNewGroupHeaderCell(ITemplatedItemsList group) else { groupHeaderCell = new TextCell(); - groupHeaderCell.SetBinding( - TextCell.TextProperty, - TypedBinding.ForSingleNestingLevel(nameof(group.Name), static (ITemplatedItemsList g) => g.Name)); + groupHeaderCell.SetBinding(TextCell.TextProperty, static (ITemplatedItemsList g) => g.Name); groupHeaderCell.BindingContext = group; } diff --git a/src/Controls/src/Core/Compatibility/Handlers/ListView/Tizen/CellContentFactory.cs b/src/Controls/src/Core/Compatibility/Handlers/ListView/Tizen/CellContentFactory.cs index 252254923948..a087f1a06cee 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/ListView/Tizen/CellContentFactory.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/ListView/Tizen/CellContentFactory.cs @@ -74,8 +74,8 @@ static View CreateContent(SectionCell sectionCell) #pragma warning restore CS0612 // Type or member is obsolete }; - text.SetBinding(Label.TextProperty, TypedBinding.ForSingleNestingLevel("Text", static (SectionCell cell) => cell.Text, source: sectionCell)); - text.SetBinding(Label.TextColorProperty, TypedBinding.ForSingleNestingLevel("TextColor", static (SectionCell cell) => cell.TextColor, source: sectionCell)); + text.SetBinding(Label.TextProperty, static (SectionCell cell) => cell.Text, source: sectionCell); + text.SetBinding(Label.TextColorProperty, static (SectionCell cell) => cell.TextColor, source: sectionCell); var layout = new Controls.StackLayout { @@ -93,15 +93,15 @@ static View CreateContent(SectionCell sectionCell) static View CreateContent(TextCell textcell) { var text = new Label(); - text.SetBinding(Label.TextProperty, TypedBinding.ForSingleNestingLevel("Text", static (TextCell cell) => cell.Text, source: textcell)); - text.SetBinding(Label.TextColorProperty, TypedBinding.ForSingleNestingLevel("TextColor", static (TextCell cell) => cell.TextColor, source: textcell)); + text.SetBinding(Label.TextProperty, static (TextCell cell) => cell.Text, source: textcell); + text.SetBinding(Label.TextColorProperty, static (TextCell cell) => cell.TextColor, source: textcell); #pragma warning disable CS0612 // Type or member is obsolete text.FontSize = Device.GetNamedSize(NamedSize.Default, typeof(Label)); #pragma warning restore CS0612 // Type or member is obsolete var detail = new Label(); - detail.SetBinding(Label.TextProperty, TypedBinding.ForSingleNestingLevel("Detail", static (TextCell cell) => cell.Detail, source: textcell)); - detail.SetBinding(Label.TextColorProperty, TypedBinding.ForSingleNestingLevel("DetailColor", static (TextCell cell) => cell.DetailColor, source: textcell)); + detail.SetBinding(Label.TextProperty, static (TextCell cell) => cell.Detail, source: textcell); + detail.SetBinding(Label.TextColorProperty, static (TextCell cell) => cell.DetailColor, source: textcell); #pragma warning disable CS0612 // Type or member is obsolete detail.FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label)); #pragma warning restore CS0612 // Type or member is obsolete @@ -139,7 +139,7 @@ static View CreateContent(ImageCell imageCell) { Aspect = Aspect.AspectFit, }; - img.SetBinding(Image.SourceProperty, TypedBinding.ForSingleNestingLevel("ImageSource", static (ImageCell cell) => cell.ImageSource, source: imageCell)); + img.SetBinding(Image.SourceProperty, static (ImageCell cell) => cell.ImageSource, source: imageCell); layout.Add(img, 0, 0); layout.Add(textcell, 1, 0); return layout; @@ -148,20 +148,15 @@ static View CreateContent(ImageCell imageCell) static View CreateContent(EntryCell entryCell) { var entry = new Entry(); - entry.SetBinding(Entry.TextProperty, - TypedBinding.ForSingleNestingLevel("Text", - static (EntryCell cell) => cell.Text, - static (cell, value) => cell.Text = value, - mode: BindingMode.TwoWay, - source: entryCell)); - entry.SetBinding(Entry.PlaceholderProperty, TypedBinding.ForSingleNestingLevel("Placeholder", static (EntryCell cell) => cell.Placeholder, source: entryCell)); - entry.SetBinding(InputView.KeyboardProperty, TypedBinding.ForSingleNestingLevel("Keyboard", static (EntryCell cell) => cell.Keyboard, source: entryCell)); - entry.SetBinding(Entry.HorizontalTextAlignmentProperty, TypedBinding.ForSingleNestingLevel("HorizontalTextAlignment", static (EntryCell cell) => cell.HorizontalTextAlignment, source: entryCell)); - entry.SetBinding(Entry.VerticalTextAlignmentProperty, TypedBinding.ForSingleNestingLevel("VerticalTextAlignment", static (EntryCell cell) => cell.VerticalTextAlignment, source: entryCell)); + entry.SetBinding(Entry.TextProperty, static (EntryCell cell) => cell.Text, mode: BindingMode.TwoWay, source: entryCell); + entry.SetBinding(Entry.PlaceholderProperty, static (EntryCell cell) => cell.Placeholder, source: entryCell); + entry.SetBinding(InputView.KeyboardProperty, static (EntryCell cell) => cell.Keyboard, source: entryCell); + entry.SetBinding(Entry.HorizontalTextAlignmentProperty, static (EntryCell cell) => cell.HorizontalTextAlignment, source: entryCell); + entry.SetBinding(Entry.VerticalTextAlignmentProperty, static (EntryCell cell) => cell.VerticalTextAlignment, source: entryCell); var label = new Label(); - label.SetBinding(Label.TextProperty, TypedBinding.ForSingleNestingLevel("Label", static (EntryCell cell) => cell.Label, source: entryCell)); - label.SetBinding(Label.TextColorProperty, TypedBinding.ForSingleNestingLevel("LabelColor", static (EntryCell cell) => cell.LabelColor, source: entryCell)); + label.SetBinding(Label.TextProperty, static (EntryCell cell) => cell.Label, source: entryCell); + label.SetBinding(Label.TextColorProperty, static (EntryCell cell) => cell.LabelColor, source: entryCell); #pragma warning disable CS0612 // Type or member is obsolete label.FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label)); #pragma warning restore CS0612 // Type or member is obsolete @@ -188,19 +183,14 @@ static View CreateContent(SwitchCell switchCell) HorizontalOptions = LayoutOptions.StartAndExpand, }; #pragma warning restore CS0618 - text.SetBinding(Label.TextProperty, TypedBinding.ForSingleNestingLevel("Text", static (SwitchCell cell) => cell.Text, source: switchCell)); + text.SetBinding(Label.TextProperty, static (SwitchCell cell) => cell.Text, source: switchCell); var sw = new Switch { HorizontalOptions = LayoutOptions.End }; - sw.SetBinding(Switch.IsToggledProperty, - TypedBinding.ForSingleNestingLevel("On", - static (SwitchCell cell) => cell.On, - static (cell, value) => cell.On = value, - mode: BindingMode.TwoWay, - source: switchCell)); - sw.SetBinding(Switch.OnColorProperty, TypedBinding.ForSingleNestingLevel("OnColor", static (SwitchCell cell) => cell.OnColor, source: switchCell)); + sw.SetBinding(Switch.IsToggledProperty, static (SwitchCell cell) => cell.On, mode: BindingMode.TwoWay, source: switchCell); + sw.SetBinding(Switch.OnColorProperty, static (SwitchCell cell) => cell.OnColor, source: switchCell); var layout = new Controls.StackLayout { diff --git a/src/Controls/src/Core/Compatibility/Handlers/ListView/Tizen/ListViewRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/ListView/Tizen/ListViewRenderer.cs index 089c4c5b2c77..36ef06dc47ed 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/ListView/Tizen/ListViewRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/ListView/Tizen/ListViewRenderer.cs @@ -98,7 +98,7 @@ protected void UpdateAdaptor(bool initialize) template = new CellWrapperTemplate(new DataTemplate(() => { var label = new TextCell(); - label.SetBinding(TextCell.TextProperty, TypedBinding.ForSingleNestingLevel(string.Empty, static (object source) => source)); + label.SetBinding(TextCell.TextProperty, static (object source) => source); return label; }), Element); } diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSearchResultsRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSearchResultsRenderer.cs index ea030bd6054a..932bc1e5104a 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSearchResultsRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSearchResultsRenderer.cs @@ -55,7 +55,7 @@ DataTemplate DefaultTemplate } #pragma warning restore CS0618 - label.SetBinding(Label.TextProperty, TypedBinding.ForSingleNestingLevel(string.Empty, static (object o) => o)); + label.SetBinding(Label.TextProperty, static (object o) => o); } label.HorizontalTextAlignment = TextAlignment.Center; diff --git a/src/Controls/src/Core/ContentConverter.cs b/src/Controls/src/Core/ContentConverter.cs index 12b78d59d789..992379bb30af 100644 --- a/src/Controls/src/Core/ContentConverter.cs +++ b/src/Controls/src/Core/ContentConverter.cs @@ -66,31 +66,45 @@ static Label ConvertToLabel(string textContent, ContentPresenter presenter) static void BindTextProperties(BindableObject content) { - BindProperty(content, TextElement.TextColorProperty, static (ITextElement te) => te.TextColor); - BindProperty(content, TextElement.CharacterSpacingProperty, static (ITextElement te) => te.CharacterSpacing); - BindProperty(content, TextElement.TextTransformProperty, static (ITextElement te) => te.TextTransform); + var source = new RelativeBindingSource(RelativeBindingSourceMode.FindAncestor, typeof(ITextElement)); + if (ShouldSetBinding(content, TextElement.TextColorProperty)) + { + content.SetBinding(TextElement.TextColorProperty, static (ITextElement te) => te.TextColor, source: source); + } + + if (ShouldSetBinding(content, TextElement.CharacterSpacingProperty)) + { + content.SetBinding(TextElement.CharacterSpacingProperty, static (ITextElement te) => te.CharacterSpacing, source: source); + } + + if (ShouldSetBinding(content, TextElement.TextTransformProperty)) + { + content.SetBinding(TextElement.TextTransformProperty, static (ITextElement te) => te.TextTransform, source: source); + } } static void BindFontProperties(BindableObject content) { - BindProperty(content, FontElement.FontAttributesProperty, static (IFontElement fe) => fe.FontAttributes); - BindProperty(content, FontElement.FontSizeProperty, static (IFontElement fe) => fe.FontSize); - BindProperty(content, FontElement.FontFamilyProperty, static (IFontElement fe) => fe.FontFamily); - } + var source = new RelativeBindingSource(RelativeBindingSourceMode.FindAncestor, typeof(IFontElement)); + if (ShouldSetBinding(content, FontElement.FontAttributesProperty)) + { + content.SetBinding(FontElement.FontAttributesProperty, static (IFontElement fe) => fe.FontAttributes, source: source); + } - static void BindProperty( - BindableObject content, - BindableProperty property, - Func getter) - { - if (content.IsSet(property) || content.GetIsBound(property)) + if (ShouldSetBinding(content, FontElement.FontSizeProperty)) { - // Don't override the property if user has already set it - return; + content.SetBinding(FontElement.FontSizeProperty, static (IFontElement fe) => fe.FontSize, source: source); } - content.SetBinding(property, TypedBinding.ForSingleNestingLevel( - property.PropertyName, getter, source: new RelativeBindingSource(RelativeBindingSourceMode.FindAncestor, typeof(TSource)))); + if (ShouldSetBinding(content, FontElement.FontFamilyProperty)) + { + content.SetBinding(FontElement.FontFamilyProperty, static (IFontElement fe) => fe.FontFamily, source: source); + } + } + + static bool ShouldSetBinding(BindableObject content, BindableProperty property) + { + return !content.IsSet(property) && !content.GetIsBound(property); } static bool HasTemplateAncestor(ContentPresenter presenter, Type type) diff --git a/src/Controls/src/Core/ContentPresenter.cs b/src/Controls/src/Core/ContentPresenter.cs index d500c2032908..546b237dda30 100644 --- a/src/Controls/src/Core/ContentPresenter.cs +++ b/src/Controls/src/Core/ContentPresenter.cs @@ -17,14 +17,12 @@ public class ContentPresenter : Compatibility.Layout, IContentView /// public ContentPresenter() { - SetBinding( + this.SetBinding( ContentProperty, - TypedBinding.ForSingleNestingLevel( - nameof(IContentView.Content), - static (IContentView view) => view.Content, - source: RelativeBindingSource.TemplatedParent, - converter: new ContentConverter(), - converterParameter: this)); + static (IContentView view) => view.Content, + source: RelativeBindingSource.TemplatedParent, + converter: new ContentConverter(), + converterParameter: this); } /// diff --git a/src/Controls/src/Core/Controls.Core.csproj b/src/Controls/src/Core/Controls.Core.csproj index 393658381597..213975bc7154 100644 --- a/src/Controls/src/Core/Controls.Core.csproj +++ b/src/Controls/src/Core/Controls.Core.csproj @@ -45,6 +45,18 @@ + + $(InterceptorsPreviewNamespaces);Microsoft.Maui.Controls.Generated + + $(CompilerResponseFile);WorkaroundXamlPreCompilePreviewFeatures.rsp + + + + + diff --git a/src/Controls/src/Core/Handlers/Items/Tizen/ItemTemplateAdaptor.cs b/src/Controls/src/Core/Handlers/Items/Tizen/ItemTemplateAdaptor.cs index ef1778ba63eb..82e7a05f34ab 100644 --- a/src/Controls/src/Core/Handlers/Items/Tizen/ItemTemplateAdaptor.cs +++ b/src/Controls/src/Core/Handlers/Items/Tizen/ItemTemplateAdaptor.cs @@ -436,7 +436,7 @@ static View CreateView() { TextColor = Colors.Black, }; - label.SetBinding(XLabel.TextProperty, TypedBinding.ForSingleNestingLevel(string.Empty, static (object source) => source, converter: new ToTextConverter())); + label.SetBinding(XLabel.TextProperty, static (object source) => source, converter: new ToTextConverter()); return new Controls.StackLayout { diff --git a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellContentItemAdaptor.cs b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellContentItemAdaptor.cs index 16ebaa5df07d..00ada2dfd7a6 100644 --- a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellContentItemAdaptor.cs +++ b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellContentItemAdaptor.cs @@ -29,9 +29,9 @@ public override NView CreateNativeView(int index) var nativeView = base.CreateNativeView(index); var view = GetTemplatedView(nativeView); - view?.SetBinding(ShellContentItemView.SelectedTextColorProperty, TypedBinding.ForSingleNestingLevel("TitleColor", static (ItemAppearance appearance) => appearance.TitleColor, source: _itemAppearance)); - view?.SetBinding(ShellContentItemView.SelectedBarColorProperty, TypedBinding.ForSingleNestingLevel("ForegroundColor", static (ItemAppearance appearance) => appearance.ForegroundColor, source: _itemAppearance)); - view?.SetBinding(ShellContentItemView.UnselectedColorProperty, TypedBinding.ForSingleNestingLevel("UnselectedColor", static (ItemAppearance appearance) => appearance.UnselectedColor, source: _itemAppearance)); + view?.SetBinding(ShellContentItemView.SelectedTextColorProperty, static (ItemAppearance appearance) => appearance.TitleColor, source: _itemAppearance); + view?.SetBinding(ShellContentItemView.SelectedBarColorProperty, static (ItemAppearance appearance) => appearance.ForegroundColor, source: _itemAppearance); + view?.SetBinding(ShellContentItemView.UnselectedColorProperty, static (ItemAppearance appearance) => appearance.UnselectedColor, source: _itemAppearance); return nativeView; } diff --git a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellContentItemView.cs b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellContentItemView.cs index 6d0999d95134..9141ef4ca5fe 100644 --- a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellContentItemView.cs +++ b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellContentItemView.cs @@ -63,7 +63,7 @@ void InitializeComponent() HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, }; - _label.SetBinding(Label.TextProperty, TypedBinding.ForSingleNestingLevel("Title", static (BaseShellItem item) => item.Title)); + _label.SetBinding(Label.TextProperty, static (BaseShellItem item) => item.Title); _bar = new BoxView { diff --git a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellFlyoutItemView.cs b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellFlyoutItemView.cs index 020ccc33802f..cb068265dfd4 100644 --- a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellFlyoutItemView.cs +++ b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellFlyoutItemView.cs @@ -36,7 +36,7 @@ void InitializeComponent() HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, }; - icon.SetBinding(Image.SourceProperty, TypedBinding.ForSingleNestingLevel("Icon", static (BaseShellItem item) => item.Icon)); + icon.SetBinding(Image.SourceProperty, static (BaseShellItem item) => item.Icon); var label = new Label { @@ -44,7 +44,7 @@ void InitializeComponent() FontSize = 16, VerticalTextAlignment = TextAlignment.Center, }; - label.SetBinding(Label.TextProperty, TypedBinding.ForSingleNestingLevel("Title", static (BaseShellItem item) => item.Title)); + label.SetBinding(Label.TextProperty, static (BaseShellItem item) => item.Title); _grid = new Grid { diff --git a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellSearchItemAdaptor.cs b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellSearchItemAdaptor.cs index b742987ff445..e6caeef1e5a5 100644 --- a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellSearchItemAdaptor.cs +++ b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellSearchItemAdaptor.cs @@ -25,7 +25,7 @@ static View CreateView() { TextColor = GColors.Black, }; - label.SetBinding(Label.TextProperty, TypedBinding.ForSingleNestingLevel(string.Empty, static (object source) => source)); + label.SetBinding(Label.TextProperty, static (object source) => source); return new Controls.StackLayout { diff --git a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellSectionItemAdaptor.cs b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellSectionItemAdaptor.cs index f950be0c95ab..6225f2349744 100644 --- a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellSectionItemAdaptor.cs +++ b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellSectionItemAdaptor.cs @@ -28,8 +28,8 @@ public override NView CreateNativeView(int index) var nativeView = base.CreateNativeView(index); var view = GetTemplatedView(nativeView); - view?.SetBinding(ShellSectionItemView.SelectedColorProperty, TypedBinding.ForSingleNestingLevel("TitleColor", static (ItemAppearance appearance) => appearance.TitleColor, source: _itemAppearance)); - view?.SetBinding(ShellSectionItemView.UnselectedColorProperty, TypedBinding.ForSingleNestingLevel("UnselectedColor", static (ItemAppearance appearance) => appearance.UnselectedColor, source: _itemAppearance)); + view?.SetBinding(ShellSectionItemView.SelectedColorProperty, static (ItemAppearance appearance) => appearance.TitleColor, source: _itemAppearance); + view?.SetBinding(ShellSectionItemView.UnselectedColorProperty, static (ItemAppearance appearance) => appearance.UnselectedColor, source: _itemAppearance); return nativeView; } diff --git a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellSectionItemView.cs b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellSectionItemView.cs index 5989f9244a9c..ec33c2b5d160 100644 --- a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellSectionItemView.cs +++ b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellSectionItemView.cs @@ -122,7 +122,7 @@ View CreateIconView() VerticalOptions = LayoutOptions.Center, }; - _icon.SetBinding(Path.DataProperty, TypedBinding.ForSingleNestingLevel("IconPath", static (ShellItemView.MoreItem item) => item.IconPath, converter: new IconConverter())); + _icon.SetBinding(Path.DataProperty, static (ShellItemView.MoreItem item) => item.IconPath, converter: new IconConverter()); return _icon; } else @@ -133,7 +133,7 @@ View CreateIconView() VerticalOptions = LayoutOptions.Center, }; - _icon.SetBinding(Image.SourceProperty, TypedBinding.ForSingleNestingLevel("Icon", static (BaseShellItem item) => item.Icon)); + _icon.SetBinding(Image.SourceProperty, static (BaseShellItem item) => item.Icon); return _icon; } } @@ -150,11 +150,11 @@ View CreateTextView() if (_isMoreItem) { - _label.SetBinding(Label.TextProperty, TypedBinding.ForSingleNestingLevel("Title", static (ShellItemView.MoreItem item) => item.Title)); + _label.SetBinding(Label.TextProperty, static (ShellItemView.MoreItem item) => item.Title); } else { - _label.SetBinding(Label.TextProperty, TypedBinding.ForSingleNestingLevel("Title", static (BaseShellItem item) => item.Title)); + _label.SetBinding(Label.TextProperty, static (BaseShellItem item) => item.Title); } return _label; diff --git a/src/Controls/src/Core/Items/CarouselView.cs b/src/Controls/src/Core/Items/CarouselView.cs index b15a5406b36a..8b45cb00b885 100644 --- a/src/Controls/src/Core/Items/CarouselView.cs +++ b/src/Controls/src/Core/Items/CarouselView.cs @@ -209,17 +209,8 @@ static void LinkToIndicatorView(CarouselView carouselView, IndicatorView indicat if (indicatorView == null) return; - indicatorView.SetBinding(IndicatorView.PositionProperty, TypedBinding.ForSingleNestingLevel( - nameof(CarouselView.Position), - getter: static (CarouselView carousel) => carousel.Position, - setter: static (carousel, val) => carousel.Position = val, - source: carouselView)); - - indicatorView.SetBinding(IndicatorView.ItemsSourceProperty, TypedBinding.ForSingleNestingLevel( - nameof(CarouselView.ItemsSource), - getter: static (CarouselView carousel) => carousel.ItemsSource, - setter: static (carousel, val) => carousel.ItemsSource = val, - source: carouselView)); + indicatorView.SetBinding(IndicatorView.PositionProperty, static (CarouselView carousel) => carousel.Position, source: carouselView); + indicatorView.SetBinding(IndicatorView.ItemsSourceProperty, static (CarouselView carousel) => carousel.ItemsSource, source: carouselView); } /// diff --git a/src/Controls/src/Core/ListView/ListView.cs b/src/Controls/src/Core/ListView/ListView.cs index 7b62a022d641..2ecbf95b8c8a 100644 --- a/src/Controls/src/Core/ListView/ListView.cs +++ b/src/Controls/src/Core/ListView/ListView.cs @@ -411,13 +411,7 @@ public void ScrollTo(object item, object group, ScrollToPosition position, bool protected override Cell CreateDefault(object item) { TextCell textCell = new TextCell(); - textCell.SetBinding( - TextCell.TextProperty, - TypedBinding.ForSingleNestingLevel( - propertyName: string.Empty, - getter: static (object cell) => cell, - mode: BindingMode.OneWay, - converter: _toStringValueConverter)); + textCell.SetBinding(TextCell.TextProperty, static (object cell) => cell, BindingMode.OneWay, _toStringValueConverter); return textCell; } diff --git a/src/Controls/src/Core/RadioButton/RadioButton.cs b/src/Controls/src/Core/RadioButton/RadioButton.cs index 92d692960e17..e2509ac29aad 100644 --- a/src/Controls/src/Core/RadioButton/RadioButton.cs +++ b/src/Controls/src/Core/RadioButton/RadioButton.cs @@ -450,41 +450,21 @@ static View BuildDefaultTemplate() Padding = 6 }; - void BindToTemplatedParent( - BindableProperty property, - Func getter, - string radioButtonPropertyName = null, - IValueConverter converter = null) - { - border.SetBinding(property, TypedBinding.ForSingleNestingLevel(radioButtonPropertyName ?? property.PropertyName, - getter, source: RelativeBindingSource.TemplatedParent, converter: converter)); - } - - BindToTemplatedParent(BackgroundColorProperty, static (RadioButton rb) => rb.BackgroundColor); - BindToTemplatedParent(HorizontalOptionsProperty, static (RadioButton rb) => rb.HorizontalOptions); - BindToTemplatedParent(MarginProperty, static (RadioButton rb) => rb.Margin); - BindToTemplatedParent(OpacityProperty, static (RadioButton rb) => rb.Opacity); - BindToTemplatedParent(RotationProperty, static (RadioButton rb) => rb.Rotation); - BindToTemplatedParent(ScaleProperty, static (RadioButton rb) => rb.Scale); - BindToTemplatedParent(ScaleXProperty, static (RadioButton rb) => rb.ScaleX); - BindToTemplatedParent(ScaleYProperty, static (RadioButton rb) => rb.ScaleY); - BindToTemplatedParent(TranslationYProperty, static (RadioButton rb) => rb.TranslationY); - BindToTemplatedParent(TranslationXProperty, static (RadioButton rb) => rb.TranslationX); - BindToTemplatedParent(VerticalOptionsProperty, static (RadioButton rb) => rb.VerticalOptions); - - BindToTemplatedParent( - Border.StrokeProperty, - static (RadioButton rb) => rb.BorderColor, - radioButtonPropertyName: nameof(RadioButton.BorderColor)); - BindToTemplatedParent( - Border.StrokeShapeProperty, - static (RadioButton rb) => rb.CornerRadius, - radioButtonPropertyName: nameof(RadioButton.CornerRadius), - converter: new CornerRadiusToShape()); - BindToTemplatedParent( - Border.StrokeThicknessProperty, - static (RadioButton rb) => rb.BorderWidth, - radioButtonPropertyName: nameof(RadioButton.BorderWidth)); + border.SetBinding(BackgroundColorProperty, static (RadioButton rb) => rb.BackgroundColor, source: RelativeBindingSource.TemplatedParent); + border.SetBinding(HorizontalOptionsProperty, static (RadioButton rb) => rb.HorizontalOptions, source: RelativeBindingSource.TemplatedParent); + border.SetBinding(MarginProperty, static (RadioButton rb) => rb.Margin, source: RelativeBindingSource.TemplatedParent); + border.SetBinding(OpacityProperty, static (RadioButton rb) => rb.Opacity, source: RelativeBindingSource.TemplatedParent); + border.SetBinding(RotationProperty, static (RadioButton rb) => rb.Rotation, source: RelativeBindingSource.TemplatedParent); + border.SetBinding(ScaleProperty, static (RadioButton rb) => rb.Scale, source: RelativeBindingSource.TemplatedParent); + border.SetBinding(ScaleXProperty, static (RadioButton rb) => rb.ScaleX, source: RelativeBindingSource.TemplatedParent); + border.SetBinding(ScaleYProperty, static (RadioButton rb) => rb.ScaleY, source: RelativeBindingSource.TemplatedParent); + border.SetBinding(TranslationYProperty, static (RadioButton rb) => rb.TranslationY, source: RelativeBindingSource.TemplatedParent); + border.SetBinding(TranslationXProperty, static (RadioButton rb) => rb.TranslationX, source: RelativeBindingSource.TemplatedParent); + border.SetBinding(VerticalOptionsProperty, static (RadioButton rb) => rb.VerticalOptions, source: RelativeBindingSource.TemplatedParent); + + border.SetBinding(Border.StrokeProperty, static (RadioButton rb) => rb.BorderColor, source: RelativeBindingSource.TemplatedParent); + border.SetBinding(Border.StrokeShapeProperty, static (RadioButton rb) => rb.CornerRadius, source: RelativeBindingSource.TemplatedParent, converter: new CornerRadiusToShape()); + border.SetBinding(Border.StrokeThicknessProperty, static (RadioButton rb) => rb.BorderWidth, source: RelativeBindingSource.TemplatedParent); var grid = new Grid { @@ -583,20 +563,8 @@ void BindToTemplatedParent( out checkMarkFillVisualStateDark); } - contentPresenter.SetBinding( - MarginProperty, - TypedBinding.ForSingleNestingLevel( - nameof(RadioButton.Padding), - static (RadioButton radio) => radio.Padding, - mode: BindingMode.OneWay, - source: RelativeBindingSource.TemplatedParent)); - contentPresenter.SetBinding( - BackgroundColorProperty, - TypedBinding.ForSingleNestingLevel( - nameof(RadioButton.BackgroundColor), - static (RadioButton radio) => radio.BackgroundColor, - mode: BindingMode.OneWay, - source: RelativeBindingSource.TemplatedParent)); + contentPresenter.SetBinding(MarginProperty, static (RadioButton radio) => radio.Padding, BindingMode.OneWay, source: RelativeBindingSource.TemplatedParent); + contentPresenter.SetBinding(BackgroundColorProperty, static (RadioButton radio) => radio.BackgroundColor, BindingMode.OneWay, source: RelativeBindingSource.TemplatedParent); grid.Add(normalEllipse); grid.Add(checkMark); diff --git a/src/Controls/src/Core/Shell/BaseShellItem.cs b/src/Controls/src/Core/Shell/BaseShellItem.cs index 3712380373ad..09e61c8c77ad 100644 --- a/src/Controls/src/Core/Shell/BaseShellItem.cs +++ b/src/Controls/src/Core/Shell/BaseShellItem.cs @@ -553,12 +553,7 @@ internal static DataTemplate CreateDefaultFlyoutItemCell(BindableObject bo) // just bind the semantic description to the title if (!g.IsSet(SemanticProperties.DescriptionProperty)) { - g.SetBinding( - SemanticProperties.DescriptionProperty, - TypedBinding.ForSingleNestingLevel( - nameof(BaseShellItem.Title), - static (BaseShellItem item) => item.Title, - static (item, val) => item.Title = val)); + g.SetBinding(SemanticProperties.DescriptionProperty, static (BaseShellItem item) => item.Title); } } } diff --git a/src/Controls/src/Core/Shell/MenuShellItem.cs b/src/Controls/src/Core/Shell/MenuShellItem.cs index 802304eb9dcd..afae10213a9e 100644 --- a/src/Controls/src/Core/Shell/MenuShellItem.cs +++ b/src/Controls/src/Core/Shell/MenuShellItem.cs @@ -14,34 +14,11 @@ internal MenuShellItem(MenuItem menuItem) MenuItem = menuItem; MenuItem.Parent = this; Shell.SetFlyoutItemIsVisible(this, Shell.GetFlyoutItemIsVisible(menuItem)); - SetBinding( - TitleProperty, - TypedBinding.ForSingleNestingLevel( - nameof(MenuItem.Text), - static (MenuItem item) => item.Text, - mode: BindingMode.OneWay, - source: menuItem)); - SetBinding( - IconProperty, - TypedBinding.ForSingleNestingLevel( - nameof(MenuItem.IconImageSource), - static (MenuItem item) => item.IconImageSource, - mode: BindingMode.OneWay, - source: menuItem)); - SetBinding( - FlyoutIconProperty, - TypedBinding.ForSingleNestingLevel( - nameof(MenuItem.IconImageSource), - static (MenuItem item) => item.IconImageSource, - mode: BindingMode.OneWay, - source: menuItem)); - SetBinding( - AutomationIdProperty, - TypedBinding.ForSingleNestingLevel( - nameof(MenuItem.AutomationId), - static (MenuItem item) => item.AutomationId, - mode: BindingMode.OneWay, - source: menuItem)); + + this.SetBinding(TitleProperty, static (MenuItem item) => item.Text, BindingMode.OneWay, source: menuItem); + this.SetBinding(IconProperty, static (MenuItem item) => item.IconImageSource, BindingMode.OneWay, source: menuItem); + this.SetBinding(FlyoutIconProperty, static (MenuItem item) => item.IconImageSource, BindingMode.OneWay, source: menuItem); + this.SetBinding(AutomationIdProperty, static (MenuItem item) => item.AutomationId, BindingMode.OneWay, source: menuItem); MenuItem.PropertyChanged += OnMenuItemPropertyChanged; } diff --git a/src/Controls/src/Core/Shell/ShellContent.cs b/src/Controls/src/Core/Shell/ShellContent.cs index 0e4f9ce43d49..bf59e4901f69 100644 --- a/src/Controls/src/Core/Shell/ShellContent.cs +++ b/src/Controls/src/Core/Shell/ShellContent.cs @@ -213,27 +213,9 @@ public static implicit operator ShellContent(TemplatedPage page) shellContent.Route = Routing.GenerateImplicitRoute(pageRoute); shellContent.Content = page; - shellContent.SetBinding( - TitleProperty, - TypedBinding.ForSingleNestingLevel( - nameof(TemplatedPage.Title), - static (TemplatedPage page) => page.Title, - mode: BindingMode.OneWay, - source: page)); - shellContent.SetBinding( - IconProperty, - TypedBinding.ForSingleNestingLevel( - nameof(TemplatedPage.IconImageSource), - static (TemplatedPage page) => page.IconImageSource, - mode: BindingMode.OneWay, - source: page)); - shellContent.SetBinding( - FlyoutIconProperty, - TypedBinding.ForSingleNestingLevel( - nameof(TemplatedPage.IconImageSource), - static (TemplatedPage page) => page.IconImageSource, - mode: BindingMode.OneWay, - source: page)); + shellContent.SetBinding(TitleProperty, static (TemplatedPage page) => page.Title, BindingMode.OneWay, source: page); + shellContent.SetBinding(IconProperty, static (TemplatedPage page) => page.IconImageSource, BindingMode.OneWay, source: page); + shellContent.SetBinding(FlyoutIconProperty, static (TemplatedPage page) => page.IconImageSource, BindingMode.OneWay, source: page); return shellContent; } diff --git a/src/Controls/src/Core/Shell/ShellItem.cs b/src/Controls/src/Core/Shell/ShellItem.cs index 0f1d0bf7854b..75f5802cd0b3 100644 --- a/src/Controls/src/Core/Shell/ShellItem.cs +++ b/src/Controls/src/Core/Shell/ShellItem.cs @@ -223,34 +223,10 @@ internal static ShellItem CreateFromShellSection(ShellSection shellSection) result.Route = Routing.GenerateImplicitRoute(shellSection.Route); result.Items.Add(shellSection); - result.SetBinding( - TitleProperty, - TypedBinding.ForSingleNestingLevel( - nameof(ShellSection.Title), - static (ShellSection section) => section.Title, - mode: BindingMode.OneWay, - source: shellSection)); - result.SetBinding( - IconProperty, - TypedBinding.ForSingleNestingLevel( - nameof(ShellSection.Icon), - static (ShellSection section) => section.Icon, - mode: BindingMode.OneWay, - source: shellSection)); - result.SetBinding( - FlyoutDisplayOptionsProperty, - TypedBinding.ForSingleNestingLevel( - nameof(ShellSection.FlyoutDisplayOptions), - static (ShellSection section) => section.FlyoutDisplayOptions, - mode: BindingMode.OneTime, - source: shellSection)); - result.SetBinding( - FlyoutIconProperty, - TypedBinding.ForSingleNestingLevel( - nameof(ShellSection.FlyoutIcon), - static (ShellSection section) => section.FlyoutIcon, - mode: BindingMode.OneWay, - source: shellSection)); + result.SetBinding(TitleProperty, static (ShellSection section) => section.Title, BindingMode.OneWay, source: shellSection); + result.SetBinding(IconProperty, static (ShellSection section) => section.Icon, BindingMode.OneWay, source: shellSection); + result.SetBinding(FlyoutDisplayOptionsProperty, static (ShellSection section) => section.FlyoutDisplayOptions, BindingMode.OneTime, source: shellSection); + result.SetBinding(FlyoutIconProperty, static (ShellSection section) => section.FlyoutIcon, BindingMode.OneWay, source: shellSection); return result; } diff --git a/src/Controls/src/Core/Shell/ShellSection.cs b/src/Controls/src/Core/Shell/ShellSection.cs index aa83ce550e82..e5b62bc83075 100644 --- a/src/Controls/src/Core/Shell/ShellSection.cs +++ b/src/Controls/src/Core/Shell/ShellSection.cs @@ -293,27 +293,9 @@ internal static ShellSection CreateFromShellContent(ShellContent shellContent) shellSection.Items.Add(shellContent); - shellSection.SetBinding( - TitleProperty, - TypedBinding.ForSingleNestingLevel( - nameof(BaseShellItem.Title), - static (BaseShellItem item) => item.Title, - mode: BindingMode.OneWay, - source: shellContent)); - shellSection.SetBinding( - IconProperty, - TypedBinding.ForSingleNestingLevel( - nameof(BaseShellItem.Icon), - static (BaseShellItem item) => item.Icon, - mode: BindingMode.OneWay, - source: shellContent)); - shellSection.SetBinding( - FlyoutIconProperty, - TypedBinding.ForSingleNestingLevel( - nameof(BaseShellItem.FlyoutIcon), - static (BaseShellItem item) => item.FlyoutIcon, - mode: BindingMode.OneWay, - source: shellContent)); + shellSection.SetBinding(TitleProperty, static (BaseShellItem item) => item.Title, BindingMode.OneWay, source: shellContent); + shellSection.SetBinding(IconProperty, static (BaseShellItem item) => item.Icon, BindingMode.OneWay, source: shellContent); + shellSection.SetBinding(FlyoutIconProperty, static (BaseShellItem item) => item.FlyoutIcon, BindingMode.OneWay, source: shellContent); return shellSection; } diff --git a/src/Controls/src/Core/TabbedPage/TabbedPage.Tizen.cs b/src/Controls/src/Core/TabbedPage/TabbedPage.Tizen.cs index 763fed32e83d..11cf62260843 100644 --- a/src/Controls/src/Core/TabbedPage/TabbedPage.Tizen.cs +++ b/src/Controls/src/Core/TabbedPage/TabbedPage.Tizen.cs @@ -202,10 +202,10 @@ void InitializeComponent() Padding = new Thickness(0); HasShadow = false; BorderColor = GColors.DarkGray; - SetBinding(BackgroundProperty, TypedBinding.ForSingleNestingLevel(nameof(Microsoft.Maui.Controls.TabbedPage.BarBackground) , static (TabbedPage page) => page.BarBackground, source: _page)); - SetBinding(BackgroundColorProperty, TypedBinding.ForSingleNestingLevel(nameof(Microsoft.Maui.Controls.TabbedPage.BarBackgroundColor), static (TabbedPage page) => page.BarBackgroundColor, source: _page)); - SetBinding(SelectedTabColorProperty, TypedBinding.ForSingleNestingLevel(nameof(Microsoft.Maui.Controls.TabbedPage.SelectedTabColor), static (TabbedPage page) => page.SelectedTabColor, source: _page)); - SetBinding(UnselectedTabColorProperty, TypedBinding.ForSingleNestingLevel(nameof(Microsoft.Maui.Controls.TabbedPage.UnselectedTabColor), static (TabbedPage page) => page.UnselectedTabColor, source: _page)); + this.SetBinding(BackgroundProperty, static (TabbedPage page) => page.BarBackground, source: _page); + this.SetBinding(BackgroundColorProperty, static (TabbedPage page) => page.BarBackgroundColor, source: _page); + this.SetBinding(SelectedTabColorProperty, static (TabbedPage page) => page.SelectedTabColor, source: _page); + this.SetBinding(UnselectedTabColorProperty, static (TabbedPage page) => page.UnselectedTabColor, source: _page); var label = new XLabel { @@ -214,8 +214,8 @@ void InitializeComponent() HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, }; - label.SetBinding(XLabel.TextProperty, TypedBinding.ForSingleNestingLevel("Title", static (TabbedPage page) => page.Title, source: _page)); - label.SetBinding(XLabel.TextColorProperty, TypedBinding.ForSingleNestingLevel("BarTextColor", static (TabbedPage page) => page.BarTextColor, source: _page)); + label.SetBinding(XLabel.TextProperty, static (TabbedPage page) => page.Title, source: _page); + label.SetBinding(XLabel.TextColorProperty, static (TabbedPage page) => page.BarTextColor, source: _page); _bar = new BoxView { diff --git a/src/Controls/src/Core/TemplatedItemsList.cs b/src/Controls/src/Core/TemplatedItemsList.cs index 36bd832a0b46..a90d29d71212 100644 --- a/src/Controls/src/Core/TemplatedItemsList.cs +++ b/src/Controls/src/Core/TemplatedItemsList.cs @@ -755,6 +755,8 @@ TemplatedItemsList InsertGrouped(object item, int index) // time for right now. groupProxy.HeaderContent = _itemsView.CreateDefault(ListProxy.ProxiedEnumerable); groupProxy.HeaderContent.BindingContext = groupProxy; + // TODO: the interceptor doesn't support generics at the moment + // groupProxy.HeaderContent.SetBinding(TextCell.TextProperty, static (TemplatedItemsList list) => list.Name); groupProxy.HeaderContent.SetBinding( TextCell.TextProperty, TypedBinding.ForSingleNestingLevel( diff --git a/src/Controls/src/Core/WorkaroundXamlPreCompilePreviewFeatures.rsp b/src/Controls/src/Core/WorkaroundXamlPreCompilePreviewFeatures.rsp new file mode 100644 index 000000000000..e60a129bbc68 --- /dev/null +++ b/src/Controls/src/Core/WorkaroundXamlPreCompilePreviewFeatures.rsp @@ -0,0 +1 @@ +/features:"InterceptorsPreviewNamespaces=Microsoft.Maui.Controls.Generated" \ No newline at end of file diff --git a/src/Controls/tests/BindingSourceGen.UnitTests/BindingCodeWriterTests.cs b/src/Controls/tests/BindingSourceGen.UnitTests/BindingCodeWriterTests.cs index 79f77236c4aa..0af7ddda711d 100644 --- a/src/Controls/tests/BindingSourceGen.UnitTests/BindingCodeWriterTests.cs +++ b/src/Controls/tests/BindingSourceGen.UnitTests/BindingCodeWriterTests.cs @@ -22,28 +22,6 @@ public void BuildsCommonCode() //------------------------------------------------------------------------------ #nullable enable - namespace System.Runtime.CompilerServices - { - using System; - using System.CodeDom.Compiler; - - {{BindingCodeWriter.GeneratedCodeAttribute}} - [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] - internal sealed class InterceptsLocationAttribute : Attribute - { - public InterceptsLocationAttribute(string filePath, int line, int column) - { - FilePath = filePath; - Line = line; - Column = column; - } - - public string FilePath { get; } - public int Line { get; } - public int Column { get; } - } - } - namespace Microsoft.Maui.Controls.Generated { using System.CodeDom.Compiler; @@ -96,6 +74,28 @@ public void BuildsWholeBinding() //------------------------------------------------------------------------------ #nullable enable + namespace System.Runtime.CompilerServices + { + using System; + using System.CodeDom.Compiler; + + {{BindingCodeWriter.GeneratedCodeAttribute}} + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + file sealed class InterceptsLocationAttribute : Attribute + { + public InterceptsLocationAttribute(string filePath, int line, int column) + { + FilePath = filePath; + Line = line; + Column = column; + } + + public string FilePath { get; } + public int Line { get; } + public int Column { get; } + } + } + namespace Microsoft.Maui.Controls.Generated { using System; diff --git a/src/Controls/tests/BindingSourceGen.UnitTests/IntegrationTests.cs b/src/Controls/tests/BindingSourceGen.UnitTests/IntegrationTests.cs index a02c893936a3..1bd20dc7a40f 100644 --- a/src/Controls/tests/BindingSourceGen.UnitTests/IntegrationTests.cs +++ b/src/Controls/tests/BindingSourceGen.UnitTests/IntegrationTests.cs @@ -31,6 +31,28 @@ public void GenerateSimpleBinding() //------------------------------------------------------------------------------ #nullable enable + namespace System.Runtime.CompilerServices + { + using System; + using System.CodeDom.Compiler; + + {{BindingCodeWriter.GeneratedCodeAttribute}} + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + file sealed class InterceptsLocationAttribute : Attribute + { + public InterceptsLocationAttribute(string filePath, int line, int column) + { + FilePath = filePath; + Line = line; + Column = column; + } + + public string FilePath { get; } + public int Line { get; } + public int Column { get; } + } + } + namespace Microsoft.Maui.Controls.Generated { using System; @@ -109,6 +131,28 @@ public void GenerateSimpleBindingCreate() //------------------------------------------------------------------------------ #nullable enable + namespace System.Runtime.CompilerServices + { + using System; + using System.CodeDom.Compiler; + + {{BindingCodeWriter.GeneratedCodeAttribute}} + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + file sealed class InterceptsLocationAttribute : Attribute + { + public InterceptsLocationAttribute(string filePath, int line, int column) + { + FilePath = filePath; + Line = line; + Column = column; + } + + public string FilePath { get; } + public int Line { get; } + public int Column { get; } + } + } + namespace Microsoft.Maui.Controls.Generated { using System; @@ -262,6 +306,28 @@ public class B //------------------------------------------------------------------------------ #nullable enable + namespace System.Runtime.CompilerServices + { + using System; + using System.CodeDom.Compiler; + + {{BindingCodeWriter.GeneratedCodeAttribute}} + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + file sealed class InterceptsLocationAttribute : Attribute + { + public InterceptsLocationAttribute(string filePath, int line, int column) + { + FilePath = filePath; + Line = line; + Column = column; + } + + public string FilePath { get; } + public int Line { get; } + public int Column { get; } + } + } + namespace Microsoft.Maui.Controls.Generated { using System; @@ -365,6 +431,28 @@ public class B //------------------------------------------------------------------------------ #nullable enable + namespace System.Runtime.CompilerServices + { + using System; + using System.CodeDom.Compiler; + + {{BindingCodeWriter.GeneratedCodeAttribute}} + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + file sealed class InterceptsLocationAttribute : Attribute + { + public InterceptsLocationAttribute(string filePath, int line, int column) + { + FilePath = filePath; + Line = line; + Column = column; + } + + public string FilePath { get; } + public int Line { get; } + public int Column { get; } + } + } + namespace Microsoft.Maui.Controls.Generated { using System; @@ -573,6 +661,28 @@ public void GenerateSimpleBindingWhenNullableDisabledAndPropertyNullable(string //------------------------------------------------------------------------------ #nullable enable + namespace System.Runtime.CompilerServices + { + using System; + using System.CodeDom.Compiler; + + {{BindingCodeWriter.GeneratedCodeAttribute}} + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + file sealed class InterceptsLocationAttribute : Attribute + { + public InterceptsLocationAttribute(string filePath, int line, int column) + { + FilePath = filePath; + Line = line; + Column = column; + } + + public string FilePath { get; } + public int Line { get; } + public int Column { get; } + } + } + namespace Microsoft.Maui.Controls.Generated { using System; @@ -690,6 +800,28 @@ public class D { //------------------------------------------------------------------------------ #nullable enable + namespace System.Runtime.CompilerServices + { + using System; + using System.CodeDom.Compiler; + + {{BindingCodeWriter.GeneratedCodeAttribute}} + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + file sealed class InterceptsLocationAttribute : Attribute + { + public InterceptsLocationAttribute(string filePath, int line, int column) + { + FilePath = filePath; + Line = line; + Column = column; + } + + public string FilePath { get; } + public int Line { get; } + public int Column { get; } + } + } + namespace Microsoft.Maui.Controls.Generated { using System; @@ -808,6 +940,28 @@ public class MyPropertyClass //------------------------------------------------------------------------------ #nullable enable + namespace System.Runtime.CompilerServices + { + using System; + using System.CodeDom.Compiler; + + {{BindingCodeWriter.GeneratedCodeAttribute}} + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + file sealed class InterceptsLocationAttribute : Attribute + { + public InterceptsLocationAttribute(string filePath, int line, int column) + { + FilePath = filePath; + Line = line; + Column = column; + } + + public string FilePath { get; } + public int Line { get; } + public int Column { get; } + } + } + namespace Microsoft.Maui.Controls.Generated { using System; @@ -931,6 +1085,28 @@ public class MyPropertyClass //------------------------------------------------------------------------------ #nullable enable + namespace System.Runtime.CompilerServices + { + using System; + using System.CodeDom.Compiler; + + {{BindingCodeWriter.GeneratedCodeAttribute}} + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + file sealed class InterceptsLocationAttribute : Attribute + { + public InterceptsLocationAttribute(string filePath, int line, int column) + { + FilePath = filePath; + Line = line; + Column = column; + } + + public string FilePath { get; } + public int Line { get; } + public int Column { get; } + } + } + namespace Microsoft.Maui.Controls.Generated { using System; @@ -1041,6 +1217,28 @@ public class Wrapper //------------------------------------------------------------------------------ #nullable enable + namespace System.Runtime.CompilerServices + { + using System; + using System.CodeDom.Compiler; + + {{BindingCodeWriter.GeneratedCodeAttribute}} + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + file sealed class InterceptsLocationAttribute : Attribute + { + public InterceptsLocationAttribute(string filePath, int line, int column) + { + FilePath = filePath; + Line = line; + Column = column; + } + + public string FilePath { get; } + public int Line { get; } + public int Column { get; } + } + } + namespace Microsoft.Maui.Controls.Generated { using System; @@ -1147,6 +1345,28 @@ public class MyPropertyClass //------------------------------------------------------------------------------ #nullable enable + namespace System.Runtime.CompilerServices + { + using System; + using System.CodeDom.Compiler; + + {{BindingCodeWriter.GeneratedCodeAttribute}} + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + file sealed class InterceptsLocationAttribute : Attribute + { + public InterceptsLocationAttribute(string filePath, int line, int column) + { + FilePath = filePath; + Line = line; + Column = column; + } + + public string FilePath { get; } + public int Line { get; } + public int Column { get; } + } + } + namespace Microsoft.Maui.Controls.Generated { using System; diff --git a/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj b/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj index dd8a433035e1..8c41c5ab5e37 100644 --- a/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj +++ b/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj @@ -5,11 +5,6 @@ Microsoft.Maui.Controls.Core.UnitTests false 0114;0672;0108;0067;0168;0169;0219;0612;0618;1998 - - 9.0 Microsoft.Maui.Controls.Core.UnitTests @@ -30,6 +25,16 @@ + + $(InterceptorsPreviewNamespaces);Microsoft.Maui.Controls.Generated + + + + + diff --git a/src/Controls/tests/Core.UnitTests/MultiBindingTests.cs b/src/Controls/tests/Core.UnitTests/MultiBindingTests.cs index 9dc17cb61a42..05755dbf6230 100644 --- a/src/Controls/tests/Core.UnitTests/MultiBindingTests.cs +++ b/src/Controls/tests/Core.UnitTests/MultiBindingTests.cs @@ -1052,12 +1052,7 @@ public ExpanderControlTemplate_TypedBinding() var cp = new ContentPresenter(); Grid.SetRow(cp, 1); - cp.SetBinding(ContentPresenter.ContentProperty, - TypedBinding.ForSingleNestingLevel( - nameof(ExpanderControl.Content), - static (ExpanderControl c) => c.Content, - static (c, v) => c.Content = v, - source: RelativeBindingSource.TemplatedParent)); + cp.SetBinding(ContentPresenter.ContentProperty, static (ExpanderControl c) => c.Content, source: RelativeBindingSource.TemplatedParent); cp.SetBinding(ContentPresenter.IsVisibleProperty, new MultiBinding { Bindings = { diff --git a/src/Controls/tests/Core.UnitTests/RelativeSourceBindingTests.cs b/src/Controls/tests/Core.UnitTests/RelativeSourceBindingTests.cs index d1b4aef63e63..364ced599186 100644 --- a/src/Controls/tests/Core.UnitTests/RelativeSourceBindingTests.cs +++ b/src/Controls/tests/Core.UnitTests/RelativeSourceBindingTests.cs @@ -32,13 +32,7 @@ public void RelativeSourceSelfBinding_TypedBinding() { StyleId = "label1" }; - label.SetBinding( - Label.TextProperty, - TypedBinding.ForSingleNestingLevel( - nameof(StackLayout.StyleId), - static (Label label) => label.StyleId, - static (label, value) => label.StyleId = value, - source: RelativeBindingSource.Self)); + label.SetBinding(Label.TextProperty, static (Label label) => label.StyleId, source: RelativeBindingSource.Self); Assert.Equal(label.Text, label.StyleId); label.StyleId = "label2"; @@ -72,13 +66,7 @@ public void RelativeSourceBinding_FindAncestor_TypedBinding() var label = new Label(); stack.Children.Add(label); - label.SetBinding( - Label.TextProperty, - TypedBinding.ForSingleNestingLevel( - nameof(StackLayout.StyleId), - static (StackLayout stack) => stack.StyleId, - static (stack, value) => stack.StyleId = value, - source: new RelativeBindingSource(RelativeBindingSourceMode.FindAncestor, typeof(StackLayout), 1))); + label.SetBinding(Label.TextProperty, static (StackLayout stack) => stack.StyleId, source: new RelativeBindingSource(RelativeBindingSourceMode.FindAncestor, typeof(StackLayout), 1)); Assert.Equal("stack1", label.Text); stack.StyleId = "stack2"; @@ -114,13 +102,7 @@ public void RelativeSourceBinding_TemplatedParent_TypedBinding() var template = new ControlTemplate(() => { label = new Label(); - label.SetBinding( - Label.TextProperty, - TypedBinding.ForSingleNestingLevel( - nameof(StackLayout.StyleId), - static (Frame frame) => frame.StyleId, - static (frame, value) => frame.StyleId = value, - source: RelativeBindingSource.TemplatedParent)); + label.SetBinding(Label.TextProperty, static (Frame frame) => frame.StyleId, source: RelativeBindingSource.TemplatedParent); return label; }); @@ -410,48 +392,18 @@ public void RelativeSourceAncestorTypeBinding_TypedBinding() stack1.Children.Add(stack0); stack0.Children.Add(grid); - label0.SetBinding(Label.TextProperty, - TypedBinding.ForSingleNestingLevel( - nameof(PersonViewModel.Name), - static (PersonViewModel vm) => vm.Name, - static (vm, value) => vm.Name = value, - source: new RelativeBindingSource(RelativeBindingSourceMode.FindAncestorBindingContext, typeof(PersonViewModel), 1))); - label0.SetBinding(Label.TextColorProperty, - TypedBinding.ForSingleNestingLevel( - nameof(StackLayout.BackgroundColor), - static (StackLayout stack) => stack.BackgroundColor, - static (stack, value) => stack.BackgroundColor = value, - source: new RelativeBindingSource(RelativeBindingSourceMode.FindAncestor, typeof(StackLayout), 1))); + label0.SetBinding(Label.TextProperty, static (PersonViewModel vm) => vm.Name, source: new RelativeBindingSource(RelativeBindingSourceMode.FindAncestorBindingContext, typeof(PersonViewModel), 1)); + label0.SetBinding(Label.TextColorProperty, static (StackLayout stack) => stack.BackgroundColor, source: new RelativeBindingSource(RelativeBindingSourceMode.FindAncestor, typeof(StackLayout), 1)); Assert.Null(label0.Text); Assert.Equal(Label.TextColorProperty.DefaultValue, label0.TextColor); - label1.SetBinding(Label.TextProperty, - TypedBinding.ForSingleNestingLevel( - nameof(PersonViewModel.Name), - static (PersonViewModel vm) => vm.Name, - static (vm, value) => vm.Name = value, - source: new RelativeBindingSource(RelativeBindingSourceMode.FindAncestorBindingContext, typeof(PersonViewModel), 2))); - label1.SetBinding(Label.TextColorProperty, - TypedBinding.ForSingleNestingLevel( - nameof(StackLayout.BackgroundColor), - static (StackLayout stack) => stack.BackgroundColor, - static (stack, value) => stack.BackgroundColor = value, - source: new RelativeBindingSource(RelativeBindingSourceMode.FindAncestor, typeof(StackLayout), 2))); + label1.SetBinding(Label.TextProperty, static (PersonViewModel vm) => vm.Name, source: new RelativeBindingSource(RelativeBindingSourceMode.FindAncestorBindingContext, typeof(PersonViewModel), 2)); + label1.SetBinding(Label.TextColorProperty, static (StackLayout stack) => stack.BackgroundColor, source: new RelativeBindingSource(RelativeBindingSourceMode.FindAncestor, typeof(StackLayout), 2)); Assert.Null(label1.Text); Assert.Equal(Label.TextColorProperty.DefaultValue, label1.TextColor); - label2.SetBinding(Label.TextProperty, - TypedBinding.ForSingleNestingLevel( - nameof(PersonViewModel.Name), - static (PersonViewModel vm) => vm.Name, - static (vm, value) => vm.Name = value, - source: new RelativeBindingSource(RelativeBindingSourceMode.FindAncestorBindingContext, typeof(PersonViewModel), 3))); - label2.SetBinding(Label.TextColorProperty, - TypedBinding.ForSingleNestingLevel( - nameof(StackLayout.BackgroundColor), - static (StackLayout vm) => vm.BackgroundColor, - static (vm, value) => vm.BackgroundColor = value, - source: new RelativeBindingSource(RelativeBindingSourceMode.FindAncestor, typeof(StackLayout), 3))); + label2.SetBinding(Label.TextProperty, static (PersonViewModel vm) => vm.Name, source: new RelativeBindingSource(RelativeBindingSourceMode.FindAncestorBindingContext, typeof(PersonViewModel), 3)); + label2.SetBinding(Label.TextColorProperty, static (StackLayout vm) => vm.BackgroundColor, source: new RelativeBindingSource(RelativeBindingSourceMode.FindAncestor, typeof(StackLayout), 3)); Assert.Null(label2.Text); Assert.Equal(Label.TextColorProperty.DefaultValue, label2.TextColor); @@ -614,7 +566,7 @@ public void RelativeSourceAncestorTypeBinding_TypedBinding() Assert.Null(label2.Text); } - class PersonViewModel + internal class PersonViewModel { public string Name { get; set; } }