CommunityToolkit / Maui

The .NET MAUI Community Toolkit is a community-created library that contains .NET MAUI Extensions, Advanced UI/UX Controls, and Behaviors to help make your life as a .NET MAUI developer easier
https://learn.microsoft.com/dotnet/communitytoolkit/maui
MIT License
2.26k stars 396 forks source link

[BUG] Decorating the Border control with anonymous Style , Popup will crash the program in Windows #1632

Closed jevonsflash closed 3 months ago

jevonsflash commented 10 months ago

Is there an existing issue for this?

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

When the ShowPopup method is called, the following error occurs:

image image

Expected Behavior

the popup view appears.

Steps To Reproduce

Create a Style in the ResourceDictionary like this:

<Style TargetType="Border">
    <Setter Property="StrokeShape"
            Value="RoundRectangle 5" />
    <Setter Property="Stroke"
            Value="{AppThemeBinding Light={StaticResource LightCardBackgroundColor}, Dark={StaticResource DarkCardBackgroundColor}}" />
    <Setter Property="BackgroundColor"
            Value="{AppThemeBinding Light={StaticResource LightCardBackgroundColor}, Dark={StaticResource DarkCardBackgroundColor}}" />
</Style>

And create a popup control like this:

<?xml version="1.0" encoding="utf-8" ?>
<toolkit:Popup xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
       xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                x:Class="MatoProductivity.Views.AppActionSettingPage"
                Opened="PopupBase_Opened"
                Size="200,200"
                Color="Transparent"
                x:Name="MainPage"
                VerticalOptions="End"
                HorizontalOptions="Fill">
    <Border></Border>

It's worth mentioning that when Stlye is not defined anonymously, The program runs normally

this is Ok:

    <Style TargetType="Border"  x:Key="FrameEntry">
        <Setter Property="StrokeShape"
                Value="RoundRectangle 5" />
        <Setter Property="Stroke"
                Value="{AppThemeBinding Light={StaticResource LightCardBackgroundColor}, Dark={StaticResource DarkCardBackgroundColor}}" />
        <Setter Property="BackgroundColor"
                Value="{AppThemeBinding Light={StaticResource LightCardBackgroundColor}, Dark={StaticResource DarkCardBackgroundColor}}" />
    </Style>
    <Border Style="{StaticResource FrameEntry}">

Link to public reproduction project repository

https://github.com/jevonsflash/MatoProductivity

Environment

- .NET MAUI CommunityToolkit: 7.0.1
- OS: Windows 11 Build 10.0.22621
- .NET MAUI: 8.0.3

Anything else?

The stack information for InnerException is printed as follows:

在 WinRT.ExceptionHelpers.gThrow|39_0(Int32 hr) 在 ABI.Microsoft.UI.Xaml.IFrameworkElementMethods.get_ActualWidth(IObjectReference _obj) 在 Microsoft.UI.Xaml.FrameworkElement.get_ActualWidth() 在 Microsoft.Maui.Platform.ContentPanel.UpdateBorder(IShape strokeShape) 在 Microsoft.Maui.Platform.ContentPanel.UpdateBorderStroke(IBorderStroke borderStroke) 在 Microsoft.Maui.Platform.StrokeExtensions.UpdateStrokeShape(ContentPanel platformView, IBorderStroke border) 在 Microsoft.Maui.Handlers.BorderHandler.MapStrokeShape(IBorderHandler handler, IBorderView border) 在 Microsoft.Maui.Handlers.ElementHandler.UpdateValue(String property) 在 Microsoft.Maui.Controls.Border.OnPropertyChanged(String propertyName) 在 Microsoft.Maui.Controls.Border.b15_0(Object sender, PropertyChangedEventArgs e) 在 Microsoft.Maui.Controls.WeakNotifyPropertyChangedProxy.OnPropertyChanged(Object sender, PropertyChangedEventArgs e) 在 Microsoft.Maui.Controls.Element.OnPropertyChanged(String propertyName) 在 Microsoft.Maui.Controls.Shapes.RoundRectangle.OnPropertyChanged(String propertyName) 在 Microsoft.Maui.Controls.Element.SetParent(Element value) 在 Microsoft.Maui.Controls.Element.OnChildAdded(Element child) 在 Microsoft.Maui.Controls.VisualElement.OnChildAdded(Element child) 在 Microsoft.Maui.Controls.Element.AddLogicalChild(Element element) 在 Microsoft.Maui.Controls.Border.NotifyStrokeShapeChanges() 在 Microsoft.Maui.Controls.Border.<>c.<.cctor>b78_0(BindableObject bindable, Object oldvalue, Object newvalue) 在 Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, Boolean silent) 在 Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity) 在 Microsoft.Maui.Controls.BindableObject.SetValue(BindableProperty property, Object value, SetterSpecificity specificity) 在 Microsoft.Maui.Controls.Setter.Apply(BindableObject target, SetterSpecificity specificity) 在 Microsoft.Maui.Controls.Style.ApplyCore(BindableObject bindable, Style basedOn, SetterSpecificity specificity) 在 Microsoft.Maui.Controls.Style.Microsoft.Maui.Controls.IStyle.Apply(BindableObject bindable, SetterSpecificity specificity) 在 Microsoft.Maui.Controls.MergedStyle.SetStyle(IStyle implicitStyle, IList`1 classStyles, IStyle style) 在 Microsoft.Maui.Controls.MergedStyle.set_ImplicitStyle(IStyle value) 在 Microsoft.Maui.Controls.MergedStyle.OnImplicitStyleChanged() 在 Microsoft.Maui.Controls.MergedStyle.b31_0(BindableObject bindable, Object oldvalue, Object newvalue) 在 Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, Boolean silent) 在 Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity) 在 Microsoft.Maui.Controls.Element.OnResourceChanged(BindableProperty property, Object value, SetterSpecificity specificity) 在 Microsoft.Maui.Controls.Element.OnSetDynamicResource(BindableProperty property, String key, SetterSpecificity specificity) 在 Microsoft.Maui.Controls.BindableObject.SetDynamicResource(BindableProperty property, String key, SetterSpecificity specificity) 在 Microsoft.Maui.Controls.BindableObject.SetDynamicResource(BindableProperty property, String key) 在 Microsoft.Maui.Controls.MergedStyle.RegisterImplicitStyles() 在 Microsoft.Maui.Controls.MergedStyle..ctor(Type targetType, BindableObject target) 在 Microsoft.Maui.Controls.NavigableElement..ctor() 在 Microsoft.Maui.Controls.VisualElement..ctor() 在 Microsoft.Maui.Controls.View..ctor() 在 Microsoft.Maui.Controls.Border..ctor() 在 System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)

cat0363 commented 10 months ago

I defined and validated implicit styles in the ResourceDictionary in App.xaml and TestPopup.xaml.

The validation results when the style is defined in App.xaml are shown below. Since the github repository was not made public, I do not know how LightCard BackgroundColor and BackCare BackgroundColor were defined, but I defined them as follows.

[App.xaml]

<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:Maui_PasswordEntryTest"
             x:Class="PopupTest.App">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources/Styles/Colors.xaml" />
                <ResourceDictionary Source="Resources/Styles/Styles.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <Color x:Key="LightCardBackgroundColor">Blue</Color>
            <Color x:Key="DarkCardBackgroundColor">Red</Color>
            <Style TargetType="{x:Type Border}">
                <Setter Property="StrokeShape" Value="RoundRectangle 5" />
                <Setter Property="Stroke" Value="{AppThemeBinding Light={StaticResource LightCardBackgroundColor}, Dark={StaticResource DarkCardBackgroundColor}}" />
                <Setter Property="BackgroundColor" Value="{AppThemeBinding Light={StaticResource LightCardBackgroundColor}, Dark={StaticResource DarkCardBackgroundColor}}" />
            </Style>

        </ResourceDictionary>
    </Application.Resources>
</Application>

[TestPopup.xaml]

<?xml version="1.0" encoding="utf-8" ?>
<toolkit:Popup xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
             x:Class="PopupTest.TestPopup"
             Size="200,200"
             Color="Transparent"
             VerticalOptions="End"
             HorizontalOptions="Fill">
    <Border>
    </Border>
</toolkit:Popup>

https://github.com/CommunityToolkit/Maui/assets/125236133/10cba6c0-094e-4f5c-b462-81f42aef7851

The verification results when the style is defined in TestPopup.xaml are shown below.

[TestPopup.xaml]

<?xml version="1.0" encoding="utf-8" ?>
<toolkit:Popup xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
             x:Class="PopupTest.TestPopup"
             Size="200,200"
             Color="Transparent"
             VerticalOptions="End"
             HorizontalOptions="Fill">
    <toolkit:Popup.Resources>
        <ResourceDictionary>
            <Color x:Key="LightCardBackgroundColor">Blue</Color>
            <Color x:Key="DarkCardBackgroundColor">Red</Color>
            <Style TargetType="{x:Type Border}">
                <Setter Property="StrokeShape" Value="RoundRectangle 5" />
                <Setter Property="Stroke" Value="{AppThemeBinding Light={StaticResource LightCardBackgroundColor}, Dark={StaticResource DarkCardBackgroundColor}}" />
                <Setter Property="BackgroundColor" Value="{AppThemeBinding Light={StaticResource LightCardBackgroundColor}, Dark={StaticResource DarkCardBackgroundColor}}" />
            </Style>
        </ResourceDictionary>
    </toolkit:Popup.Resources>
    <Border>
    </Border>
</toolkit:Popup>

https://github.com/CommunityToolkit/Maui/assets/125236133/be747f94-8afa-47f9-928e-6eef2d2c6d7e

No exceptions occurred in either case.

By the way, the theme at the time of verification was light.

cat0363 commented 9 months ago

@jevonsflash , I get a 404 error when I try to browse the repository. Is this repository public?

dotnet-policy-service[bot] commented 3 months ago

Hi @jevonsflash. We have added the "needs reproduction" label to this issue, which indicates that we cannot take further action. This issue will be closed automatically in 5 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

vhugogarcia commented 3 months ago

Thanks @cat0363 for testing and trying to reproduce the issue, I have added the label: needs reproduction and waiting for feedback from @jevonsflash, to know if this issue is still active or no.

dotnet-policy-service[bot] commented 3 months ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 3 days. It will be closed if no further activity occurs within 2 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

dotnet-policy-service[bot] commented 3 months ago

We haven't received a reproduction sample from you. The issue is closed.