Skip to content
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

[X] inherit DataType based on attribute #25173

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Controls/src/Core/ListView/ListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Windows.Input;
using Microsoft.Extensions.Logging;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Controls.Xaml;
using Microsoft.Maui.Controls.Xaml.Diagnostics;
using Microsoft.Maui.Devices;
using Microsoft.Maui.Graphics;
Expand Down Expand Up @@ -151,6 +152,7 @@ protected override void OnBindingContextChanged()
}

/// <include file="../../docs/Microsoft.Maui.Controls/ListView.xml" path="//Member[@MemberName='GroupDisplayBinding']/Docs/*" />
[DoesNotInheritDataType]
public BindingBase GroupDisplayBinding
{
get { return _groupDisplayBinding; }
Expand All @@ -176,6 +178,7 @@ public DataTemplate GroupHeaderTemplate
}

/// <include file="../../docs/Microsoft.Maui.Controls/ListView.xml" path="//Member[@MemberName='GroupShortNameBinding']/Docs/*" />
[DoesNotInheritDataType]
public BindingBase GroupShortNameBinding
{
get { return _groupShortNameBinding; }
Expand Down
2 changes: 2 additions & 0 deletions src/Controls/src/Core/Picker/Picker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Controls.Xaml;
using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Controls
Expand Down Expand Up @@ -199,6 +200,7 @@ public TextAlignment VerticalTextAlignment

BindingBase _itemDisplayBinding;
/// <include file="../../docs/Microsoft.Maui.Controls/Picker.xml" path="//Member[@MemberName='ItemDisplayBinding']/Docs/*" />
[DoesNotInheritDataType]
public BindingBase ItemDisplayBinding
{
get { return _itemDisplayBinding; }
Expand Down
3 changes: 3 additions & 0 deletions src/Controls/src/Core/TemplatedItemsList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading.Tasks;
using Cadenza.Collections;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Controls.Xaml;
using Microsoft.Maui.Devices;

namespace Microsoft.Maui.Controls.Internals
Expand Down Expand Up @@ -100,6 +101,7 @@ event PropertyChangedEventHandler ITemplatedItemsList<TItem>.PropertyChanged
remove { PropertyChanged -= value; }
}

[DoesNotInheritDataType]
public BindingBase GroupDisplayBinding
{
get { return _groupDisplayBinding; }
Expand Down Expand Up @@ -133,6 +135,7 @@ public DataTemplate GroupHeaderTemplate

public BindableProperty GroupHeaderTemplateProperty { get; set; }

[DoesNotInheritDataType]
public BindingBase GroupShortNameBinding
{
get { return _groupShortNameBinding; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#nullable disable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: could probably remove this line, but don't block merging. 👍

using System;

namespace Microsoft.Maui.Controls.Xaml
{
internal class DoesNotInheritDataTypeAttribute : Attribute
{
}
}
8 changes: 4 additions & 4 deletions src/Controls/src/Xaml/XamlServiceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,17 +324,17 @@ static bool IsBindingContextBinding(IElementNode node)
return false;
}

static bool IsBindingBaseProperty(IElementNode node, HydrationContext context)
static bool DoesNotInheritDataType(IElementNode node, HydrationContext context)
{
if ( node.TryGetPropertyName(node.Parent, out XmlName name)
&& node.Parent is IElementNode parent
&& XamlParser.GetElementType(parent.XmlType,
new XmlLineInfo(((IXmlLineInfo)node).LineNumber, ((IXmlLineInfo)node).LinePosition),
context.RootElement.GetType().Assembly, out var xpe) is Type parentType
&& parentType.GetRuntimeProperties().FirstOrDefault(p => p.Name == name.LocalName) is PropertyInfo propertyInfo
&& propertyInfo.PropertyType == typeof(BindingBase))
&& propertyInfo.CustomAttributes.Any(ca => ca.AttributeType == typeof(DoesNotInheritDataTypeAttribute)))
{
return true;
return true;
}
return false;
}
Expand All @@ -360,7 +360,7 @@ static bool IsBindingBaseProperty(IElementNode node, HydrationContext context)
{
break;
}
if (IsBindingBaseProperty(n, context))
if (DoesNotInheritDataType(n, context))
{
break;
}
Expand Down
Loading