Skip to content
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
62 changes: 62 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue29930.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 29930, "[Windows] Setting a ContentView with a content of StaticResource Style Causes a System.Runtime.InteropServices.COMException.", PlatformAffected.UWP)]
public class Issue29930 : ContentPage
{
ContentView _mainContentView;
public Issue29930()
{
var button = new Button
{
Text = "Add ContentView",
HorizontalOptions = LayoutOptions.Center,
AutomationId = "ChangeInnerContent"
};
button.Clicked += OnButtonClicked;

_mainContentView = new ContentView();
_mainContentView.Content = new Issue29930InnerContentView();

var layout = new VerticalStackLayout
{
Spacing = 25,
Padding = new Thickness(30, 0),
VerticalOptions = LayoutOptions.Center,
Children =
{
button,
_mainContentView
}
};

Content = layout;
}
private void OnButtonClicked(object sender, EventArgs e)
{
_mainContentView.Content = new Issue29930InnerContentView() { BackgroundColor = Colors.Red };
}
}

public class Issue29930InnerContentView : ContentView
{
public Issue29930InnerContentView()
{
Application.Current.Resources ??= new ResourceDictionary();

if (!Application.Current.Resources.ContainsKey("SubContentStyle"))
{
Application.Current.Resources["SubContentStyle"] = new Style(typeof(ContentView))
{
Setters =
{
new Setter
{
Property = ContentView.ContentProperty,
Value = new Label { Text = "SubContent" }
}
}
};
}
Style = (Style)Application.Current.Resources["SubContentStyle"];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#if TEST_FAILS_ON_ANDROID // Test fails on Android , see https://github.com/dotnet/maui/issues/11812
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue29930 : _IssuesUITest
{
public Issue29930(TestDevice device) : base(device) { }

public override string Issue => "[Windows] Setting a ContentView with a content of StaticResource Style Causes a System.Runtime.InteropServices.COMException.";

[Test]
[Category(UITestCategories.Border)]
public void InnerContentViewShouldNotCrashWhenDynamicallyChange()
{
App.WaitForElement("ChangeInnerContent");
App.Tap("ChangeInnerContent");
App.WaitForElement("ChangeInnerContent");
}
}
#endif
5 changes: 5 additions & 0 deletions src/Core/src/Handlers/Border/BorderHandler.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ static partial void UpdateContent(IBorderHandler handler)
handler.PlatformView.EnsureBorderPath();

if (handler.VirtualView.PresentedContent is IView view)
{
// Detach the old handler if it exists (prevents WinUI COM exception on reuse)
view.Handler?.DisconnectHandler();
handler.PlatformView.Content = view.ToPlatform(handler.MauiContext);
}

}

protected override ContentPanel CreatePlatformView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ static void UpdateContent(IContentViewHandler handler)

if (handler.VirtualView.PresentedContent is IView view)
{
// Detach the old handler if it exists (prevents WinUI COM exception on reuse)
view.Handler?.DisconnectHandler();
handler.PlatformView.CachedChildren.Add(view.ToPlatform(handler.MauiContext));
}
}
Expand Down
Loading