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

Changing ControlTemplate on Frame dynamically from XAML with DataTrigger does not trigger change on screen #21947

Closed
the-gozo opened this issue Apr 19, 2024 · 4 comments
Labels
area-xaml XAML, CSS, Triggers, Behaviors platform/android 🤖 platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working

Comments

@the-gozo
Copy link

Description

Changing Frame's ControlTemplate with DataTriggers by clicking the Button does not reflect on screen. Looking at Live Visual Tree in VS the the child element of Frame is changing successfully, but Frame keep being empty always. Looked only on Android.

State 1:
image

State 2:
image

Frame keeps being empty.
Screenshot_1713537867

Steps to Reproduce

  1. Create a Flie new MAUI project
  2. Add a Frame with a ResourceDicionary containing two ControlTemplates.
  3. Change the Frames ControlTemplate using DataTrigger.
<?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"
             x:Class="ControlTemplatePoc.MainPage">
    <VerticalStackLayout Padding="30,0"
                         Spacing="25">
        <Button x:Name="CounterBtn"
                Text="Click me"
                SemanticProperties.Hint="Counts the number of times you click"
                Clicked="OnCounterClicked"
                HorizontalOptions="Fill" />
        <Frame x:Name="frame"
               HeightRequest="500">
            <Frame.Resources>
                <ControlTemplate x:Key="First">
                    <Label Text="First"
                           IsVisible="True" />
                </ControlTemplate>
                <ControlTemplate x:Key="Second">
                    <Label Text="Second"
                           IsVisible="True" />
                </ControlTemplate>
            </Frame.Resources>
            <Frame.Triggers>
                <DataTrigger TargetType="Frame"
                             Binding="{Binding Boolean}"
                             Value="True">
                    <Setter Property="ControlTemplate"
                            Value="{StaticResource First}" />
                </DataTrigger>
                <DataTrigger TargetType="Frame"
                             Binding="{Binding Boolean}"
                             Value="False">
                    <Setter Property="ControlTemplate"
                            Value="{StaticResource Second}" />
                </DataTrigger>
            </Frame.Triggers>
        </Frame>
    </VerticalStackLayout>
</ContentPage>
using CommunityToolkit.Mvvm.ComponentModel;

namespace ControlTemplatePoc
{
    public partial class MainPage : ContentPage
    {
        private bool _boolean;
        public MainPage()
        {
            InitializeComponent();
            BindingContext = this;
        }

        public bool Boolean 
        { 
            get => _boolean; 
            set  { _boolean = value; OnPropertyChanged(); } 
        }

        private void OnCounterClicked(object sender, EventArgs e)
        {
            Boolean = !Boolean;
            var ct = frame.ControlTemplate; //to check if ControlTemplate is being set by xaml
        }
    }

}

Link to public reproduction project repository

https://github.com/the-gozo/ControlTemplatePoc

Version with bug

8.0.10 SR3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

Nope.

Relevant log output

No response

@the-gozo the-gozo added the t/bug Something isn't working label Apr 19, 2024
@the-gozo
Copy link
Author

Maybe related:
#4135

@XamlTest XamlTest added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Apr 22, 2024
@RoiChen001
Copy link

Can repro this issue at Android platform on the latest 17.10.0 Preview 4(8.0.20).

@XamlTest
Copy link

Verified on 17.10.0 Preview 4.0(8.0.20), also repro on Windows 11, but not repro on iOS 17.2.

@PureWeen
Copy link
Member

Frame doesn't support having a ControlTemplate property. If you want to use ControlTemplates you'll need to use ContentView

@PureWeen PureWeen closed this as not planned Won't fix, can't repro, duplicate, stale May 23, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jun 24, 2024
@samhouts samhouts added the area-xaml XAML, CSS, Triggers, Behaviors label Aug 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-xaml XAML, CSS, Triggers, Behaviors platform/android 🤖 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

5 participants