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

ContentView: Setting the ControlTemplate dynamically causes the control to disappear #4135

Closed
vanka78bg opened this issue Jan 14, 2022 · 2 comments · Fixed by #7235
Closed
Assignees
Labels
area-xaml XAML, CSS, Triggers, Behaviors delighter fixed-in-6.0.400 Look for this fix in 6.0.400! high It doesn't work at all, crashes or has a big impact. p/2 Work that is important, but is currently not scheduled for release partner Issue or Request from a partner team platform/android 🤖 platform/iOS 🍎 platform/macOS 🍏 macOS / Mac Catalyst platform/windows 🪟 s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@vanka78bg
Copy link

vanka78bg commented Jan 14, 2022

Description

I have noticed that ContentView does not support setting the ControlTemplate dynamically at runtime. When the ControlTemplate is set initially in XAML or in the Page's constructor, everything works as expected. When the ControlTemplate is set at a later stage, the ContentView just disappears. Some preliminary investigation leads me to conclude this has something to do with the ContentViews Handler. If the Handler is not created yet, setting the ControlTemplate would work as expected. If the Handler is already created, setting the ControlTemplate would make the control disappear.

While debugging, I have also noticed the ContentView inherits from the legacy Layout class. Setting the ControlTemplate at runtime would invalidate the measure, but calling IView.Measure after that on the ContentView would always return a zero Size. This might be some incompatibility between the old and the new layout systems, but I have not investigated that further.

Steps to Reproduce

  1. Run the attached sample project
    • The first ContentView has a ControlTemplate set in XAML
    • The second ContentView has a custom Style specifying a ControlTemplate in XAML
    • The third and fourth ContentViews do not have a ControlTemplate specified initially
  2. Click the Set Custom Template button
    • This sets a ControlTemplate to the third ContentView. Notice the ContentView disappearing.
  3. Click the Set Custom Style button
    • This sets a Style specifying a ControlTemplate to the fourth ContentView. Notice the ContentView disappearing.

Version with bug

Preview 11

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android, Windows, macOS

Affected platform versions

I have not tested on various versions of the different platforms.

Did you find any workaround?

The only workaround I have found so far is to replace the ContentView with a new instance, that has the desired ControlTemplate set initially. This is rather inconvenient, as changing the Style of a ContentView to a new one, which might potentially update the ControlTemplate, would require re-creating the entire ContentView every time, to avoid the bug.

Relevant log output

No log output available at this time.

Sample project

TestApp.zip

@vanka78bg vanka78bg added the t/bug Something isn't working label Jan 14, 2022
@jsuarezruiz jsuarezruiz added the area-xaml XAML, CSS, Triggers, Behaviors label Jan 14, 2022
@jsuarezruiz jsuarezruiz added the partner Issue or Request from a partner team label Jan 14, 2022
@jsuarezruiz jsuarezruiz added the high It doesn't work at all, crashes or has a big impact. label Jan 20, 2022
@Amir-Care
Copy link

Repro on VS 17.2.0 Preview 2.0 [32208.484.main]

@Amir-Care Amir-Care added the s/verified Verified / Reproducible Issue ready for Engineering Triage label Mar 1, 2022
@Redth Redth added this to the 6.0.300-rc.2 milestone Mar 22, 2022
@Redth Redth modified the milestones: 6.0.300-rc.2, 6.0.300-rc.3 Apr 20, 2022
@Redth Redth modified the milestones: 6.0.300-rc.3, 6.0.300 Apr 27, 2022
@davidortinau davidortinau added p/0 Work that we can't release without p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint and removed p/0 Work that we can't release without labels Apr 28, 2022
@Redth Redth added p/2 Work that is important, but is currently not scheduled for release and removed p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint labels May 3, 2022
@samhouts samhouts modified the milestones: 6.0.300, 6.0.300-servicing May 7, 2022
@mfe-
Copy link

mfe- commented May 14, 2022

I'm having the same issue on the Windows Platform. Can't change the ControlTemplate during runtime.

                <!--<controls:CardView.Triggers>
                    <DataTrigger Binding="{Binding Player2Container.SelectedCardPlayer,Converter={StaticResource IsNullConverter}}" Value="True" 
                                 TargetType="{x:Type controls:CardView}">
                        <Setter Property="ControlTemplate" Value="{StaticResource CardViewBackControlTemplate}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Player2Container.SelectedCardPlayer,Converter={StaticResource IsNullConverter}}" Value="False" 
                                 TargetType="{x:Type controls:CardView}">
                        <Setter Property="ControlTemplate" Value="{StaticResource CardViewControlTemplate}" />
                    </DataTrigger>
                </controls:CardView.Triggers>-->

Setting it from Codebehind also doesn't change the appearance of the control.
I'm using Visual Studio 17.3.0 Preview 1.0

@ghost ghost locked as resolved and limited conversation to collaborators Jun 25, 2022
@samhouts samhouts added the fixed-in-6.0.400 Look for this fix in 6.0.400! label Feb 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-xaml XAML, CSS, Triggers, Behaviors delighter fixed-in-6.0.400 Look for this fix in 6.0.400! high It doesn't work at all, crashes or has a big impact. p/2 Work that is important, but is currently not scheduled for release partner Issue or Request from a partner team platform/android 🤖 platform/iOS 🍎 platform/macOS 🍏 macOS / Mac Catalyst platform/windows 🪟 s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

8 participants