Skip to content

Commit 26ea43c

Browse files
[XSG] SetDynamciResource (#32323)
SetDynamicResource is an implicit interface implementation for BindableObject. Cast it. - fixes #32319
1 parent 5740076 commit 26ea43c

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

src/Controls/src/SourceGen/SetPropertyHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ static bool CanSetDynamicResource(IFieldSymbol? bpFieldSymbol, INode node, Sourc
184184
}
185185

186186
static void SetDynamicResource(IndentedTextWriter writer, ILocalValue parentVar, IFieldSymbol fieldSymbol, INode valueNode, SourceGenContext context, NodeSGExtensions.GetNodeValueDelegate getNodeValue)
187-
=> writer.WriteLine($"{parentVar.ValueAccessor}.SetDynamicResource({fieldSymbol.ToFQDisplayString()}, {(getNodeValue(valueNode, context.Compilation.ObjectType)).ValueAccessor}.Key);");
187+
=> writer.WriteLine($"((global::Microsoft.Maui.Controls.Internals.IDynamicResourceHandler){parentVar.ValueAccessor}).SetDynamicResource({fieldSymbol.ToFQDisplayString()}, {(getNodeValue(valueNode, context.Compilation.ObjectType)).ValueAccessor}.Key);");
188188

189189
static bool CanConnectEvent(ILocalValue parentVar, string localName, INode valueNode, bool attached, SourceGenContext context)
190190
//FIXME check event signature
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="Microsoft.Maui.Controls.Xaml.UnitTests.Issues.Maui32319"
5+
Title="Maui32319">
6+
<ContentPage.Resources>
7+
<GridLength x:Key="height">100</GridLength>
8+
</ContentPage.Resources>
9+
<Grid
10+
x:Name="grid0">
11+
<Grid.RowDefinitions>
12+
<RowDefinition Height="14" />
13+
<RowDefinition Height="60" />
14+
<RowDefinition Height="{DynamicResource height}" />
15+
</Grid.RowDefinitions>
16+
</Grid>
17+
</ContentPage>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Microsoft.Maui.ApplicationModel;
2+
using Microsoft.Maui.Controls.Core.UnitTests;
3+
using Microsoft.Maui.Dispatching;
4+
using Microsoft.Maui.UnitTests;
5+
using NUnit.Framework;
6+
7+
namespace Microsoft.Maui.Controls.Xaml.UnitTests.Issues;
8+
9+
public partial class Maui32319 : ContentPage
10+
{
11+
public Maui32319() => InitializeComponent();
12+
13+
[TestFixture]
14+
class Test
15+
{
16+
[SetUp]
17+
public void Setup()
18+
{
19+
Application.SetCurrentApplication(new MockApplication());
20+
DispatcherProvider.SetCurrent(new DispatcherProviderStub());
21+
}
22+
23+
[TearDown] public void TearDown() => AppInfo.SetCurrent(null);
24+
25+
[Test]
26+
public void DynamicResourceOnBO([Values] XamlInflator inflator)
27+
{
28+
Assert.DoesNotThrow(() => new Maui32319(inflator));
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)