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] allow x:Type extension for BPConverter #18540

Merged
merged 1 commit into from
Jan 26, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,14 @@ public FieldReference GetBindablePropertyFieldReference(string value, ILContext
}
}
else if ((node.Parent as ElementNode)?.XmlType.NamespaceUri == XamlParser.MauiUri && (node.Parent as ElementNode)?.XmlType.Name == nameof(Trigger))
typeName = ((node.Parent as ElementNode).Properties[new XmlName("", "TargetType")] as ValueNode).Value as string;
{
var targetTypeNode = (node.Parent as ElementNode).Properties[new XmlName("", "TargetType")];
if (targetTypeNode is ValueNode valueNode)
typeName = valueNode.Value as string;
else if (targetTypeNode is ElementNode elementNode && elementNode.XmlType.Name == "TypeExtension")
typeName = (elementNode.Properties[new XmlName("", "TypeName")] as ValueNode).Value as string;

}
propertyName = parts[0];
}
else if (parts.Length == 2)
Expand Down
23 changes: 23 additions & 0 deletions src/Controls/tests/Xaml.UnitTests/Issues/Maui18324.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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.Maui18324">
<ImageButton x:Name="imageButton">
<ImageButton.Style>
<Style TargetType="ImageButton">
<Style.Triggers>
<Trigger TargetType="{x:Type ImageButton}"
Property="IsEnabled"
Value="True">
<Setter Property="BackgroundColor"
Value="Yellow" />
</Trigger>
</Style.Triggers>

</Style>

</ImageButton.Style>

</ImageButton>
</ContentPage>
49 changes: 49 additions & 0 deletions src/Controls/tests/Xaml.UnitTests/Issues/Maui18324.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using Microsoft.Maui.ApplicationModel;
using Microsoft.Maui.Controls.Core.UnitTests;
using Microsoft.Maui.Controls.Shapes;
using Microsoft.Maui.Devices;
using Microsoft.Maui.Dispatching;

using Microsoft.Maui.Graphics;
using Microsoft.Maui.UnitTests;
using NUnit.Framework;

namespace Microsoft.Maui.Controls.Xaml.UnitTests;

public partial class Maui18324 : ContentPage
{

public Maui18324() => InitializeComponent();

public Maui18324(bool useCompiledXaml)
{
//this stub will be replaced at compile time
}

[TestFixture]
class Test
{
[SetUp]
public void Setup()
{
Application.SetCurrentApplication(new MockApplication());
DispatcherProvider.SetCurrent(new DispatcherProviderStub());
}


[TearDown] public void TearDown() => AppInfo.SetCurrent(null);

[Test]
public void xTypeShoudntCrash([Values(false, true)] bool useCompiledXaml)
{
if (useCompiledXaml)
MockCompiler.Compile(typeof(Maui18324));
var page = new Maui18324(useCompiledXaml);
}
}
}