dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.24k stars 1.76k forks source link

CONTROL TEMPLATES CRASHING #12490

Closed veldfolds closed 1 year ago

veldfolds commented 1 year ago

Description

Placing control templates in the app dictionary leads to a lot of problems I haven't even bothered trying placing them in other pages "DRY". If it builds in debug in release, launching the app makes it to crash. In some cases in debug mode the control templates fail to render when instantiated in other views. I am using .NET 7 perhaps i'll have to switch back to 6

Steps to Reproduce

<?xml version = "1.0" encoding = "UTF-8" ?> <Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:Trex" x:Class="Trex.App">

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources/Styles/Colors.xaml" />
            <ResourceDictionary Source="Resources/Styles/Styles.xaml" />
        </ResourceDictionary.MergedDictionaries>

        <ControlTemplate x:Key="LabelSwitchTemplate">
            <VerticalStackLayout>
                <Label Text="{Binding SwitchTextLabel}" 
                       FontSize="40"
                       FontAttributes="Bold"
                       HorizontalOptions="Center"
                       VerticalOptions="Start"
                       TextColor="White"/>
                <ContentPresenter />
            </VerticalStackLayout>
        </ControlTemplate>
    </ResourceDictionary>
</Application.Resources>

</Application

namespace Trex { class GroundSwitch : ContentView { public static readonly BindableProperty SwitchLabelTextProperty = BindableProperty.Create(nameof(SwitchTextLabel), typeof(string), typeof(GroundSwitch));

    public string SwitchTextLabel
    {
        get => (string)GetValue(SwitchLabelTextProperty);
        set => SetValue(SwitchLabelTextProperty, value);
    }

    public GroundSwitch()
    {
    }

}

}

<?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:Trex" x:Class="Trex.VoilaPage" Title="VoilaPage">

<VerticalStackLayout>

    <local:GroundSwitch ControlTemplate="{StaticResource LabelSwitchTemplate}"
                        SwitchTextLabel="PLEASE WORK!!!!">
        <Grid WidthRequest="100"
          HeightRequest="100"
          BackgroundColor="Green" />
    </local:GroundSwitch>
</VerticalStackLayout>

only the grid will show up in the content page when built but the label defined in the control template is MIA

Link to public reproduction project repository

NA

Version with bug

7.0 (current)

Last version that worked well

6.0.312

Affected platforms

Android, Windows

Affected platform versions

Android 11, Windows 10 19044.2075

Did you find any workaround?

No response

Relevant log output

No response

ghost commented 1 year ago

Hi @veldfolds. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 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.

ghost commented 1 year ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback to reproduce the issue but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 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.