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

Dynamic resources are not applied issue for the layouts in .NET MAUI #16277

Open
Priyadharshini-Periyasamy opened this issue Jul 21, 2023 · 3 comments
Labels
area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@Priyadharshini-Periyasamy
Copy link

Priyadharshini-Periyasamy commented Jul 21, 2023

Description

When attempting to use dynamic resource binding to set properties of a layout that is a child of the ContentView, an issue arises. The problem is that the parent reference of the layout becomes null.

Below code snippet is used to reproduce the issue.

Code
public class DemoClass : View, IContentView, IVisualTreeElement
{
    private Grid grid;

    public DemoClass()
   {
        this.grid = new Grid();
        Label label = new Label();
        label.VerticalOptions = LayoutOptions.Center;
        label.HorizontalOptions = LayoutOptions.Center;
        label.Text = "Dynamic resource";
        label.SetDynamicResource(Label.TextColorProperty, "SomeColor");
        this.grid.Children.Add(label);
        this.grid.parent = this;
    }

    object IContentView.Content
    {
        get
        {
            return grid;
        }
    }

    IView IContentView.PresentedContent
    {
        get
        {
            return grid;
        }
    }

    IReadOnlyList<IVisualTreeElement> IVisualTreeElement.GetVisualChildren()
    {
        if (this.grid != null)
        {
            return new List<IVisualTreeElement>() { grid };
        }

        return new List<IVisualTreeElement>();
    }

    /// <summary>
    /// Gets the content padding.
    /// </summary>
    Thickness IPadding.Padding
    {
        get
        {
            return new Thickness(0);
        }
    }

    public Size CrossPlatformArrange(Rect bounds)
    {
        this.ArrangeContent(bounds);
        return bounds.Size;
    }

    public Size CrossPlatformMeasure(double widthConstraint, double heightConstraint)
    {
        return this.MeasureContent(widthConstraint, heightConstraint);
    }
}

[GaugeDynamicBinding.zip](https://github.com/dotnet/maui/files/12124858/GaugeDynamicBinding.zip)



Steps to Reproduce

1 Create an instance of the DemoClass in the application.
2. Use the DemoClass instance to set up a ContentView that contains the child layout, e.g., a Grid.
3. Attempt to apply dynamic resource binding on properties of the child layout (e.g., Grid) from within the DemoClass.

Link to public reproduction project repository

GaugeDynamicBinding.zip

Version with bug

7.0.49

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows : Windows 10 Enterprise 10.0.19044

Did you find any workaround?

No response

Relevant log output

No response

@Priyadharshini-Periyasamy Priyadharshini-Periyasamy added the t/bug Something isn't working label Jul 21, 2023
@PureWeen PureWeen added the area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter label Jul 21, 2023
@PureWeen PureWeen added this to the Backlog milestone Jul 21, 2023
@ghost
Copy link

ghost commented Jul 21, 2023

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

@PureWeen
Copy link
Member

The code here might help you out in NET8
#16046

@jaosnz-rep jaosnz-rep added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Feb 20, 2024
@jaosnz-rep
Copy link

Verified this issue with Visual Studio Enterprise 17.9.0 Preview 3. Can repro on .NET 7/.NET 8 Android platforms with sample project.
DynamicResourceSample.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants