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

Assigning "{x:Type ImageButton}" instead of "ImageButton" to the TargetType property of a Trigger in an ImageButton style breaks build #18324

Closed
MauiUIui opened this issue Oct 24, 2023 · 7 comments · Fixed by #18540

Comments

@MauiUIui
Copy link

MauiUIui commented Oct 24, 2023

Description

Almost all in the title. So an ImageButton doesn't allow {x:Type ImageButton} to be assigned as a value to the TargetType property in a Trigger of its style. Doing so yields the famous "Object reference not set to an instance of an object." error which prevents the build from completing. It doesn't matter where the trigger is defined (Default Style in Styles.xaml, in the control itself, in the resources of a containing element...)

Steps to Reproduce

  1. Create a MAUI app.
  2. Create an ImageButton
  3. Give it a style in which a trigger is defined and set the TargetType property of that trigger "{x:Type ImageButton}".
  4. Build fails

Link to public reproduction project repository

No response

Version with bug

8.0.0-rc.2.9373

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android, Windows, I was not able test on other platforms

Affected platform versions

No response

Did you find any workaround?

Set the TargetType property to "ImageButton" instead.

Relevant log output

No response

@MauiUIui MauiUIui added the t/bug Something isn't working label Oct 24, 2023
@MauiUIui MauiUIui changed the title Assigning "{x:Type ImageButton}" instead of "ImageButton" to the TargetType property of a Trigger of an ImageButton style breaks build Assigning "{x:Type ImageButton}" instead of "ImageButton" to the TargetType property of a Trigger in an ImageButton style breaks build Oct 25, 2023
@Eilon Eilon added the area-xaml XAML, CSS, Triggers, Behaviors label Oct 25, 2023
@mattleibow mattleibow added the s/needs-repro Attach a solution or code which reproduces the issue label Oct 25, 2023
@ghost
Copy link

ghost commented Oct 25, 2023

Hi @MauiUIui. 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.

@mattleibow
Copy link
Member

According to the docs, it should be ImageButton: https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/triggers#property-triggers

Where are you getting the x:Type from?

@MauiUIui
Copy link
Author

Where are you getting the x:Type from?

This is actually the original "form". The TargetType property is of type Type and thus should be provided a value of such type, which is originally done using the x:Type markup extension. The way it's written in the documentation you referred to is actually just a well known, well used XAML shortcut, that I usually don't use, because it dosn't always work, for example with custom types. You can read about it from its own documentation here. The link is from .NET desktop (WPF usage) but it explains it pretty well and it stayed the same over the years:

WPF supports techniques that enable specifying the value of some properties of type Type without requiring an x:Type markup extension usage. Instead, you can specify the value as a string that names the type. Examples of this are ControlTemplate.TargetType and Style.TargetType. Support for this behavior is not provided through either type converters or markup extensions. Instead, this is a deferral behavior implemented through FrameworkElementFactory.

That's why it MUST work for all controls and everywhere and it actually does with all other controls, ImageButton being the exception for now ;)

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-repro Attach a solution or code which reproduces the issue labels Oct 25, 2023
@MauiUIui
Copy link
Author

Hi @MauiUIui. 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.

Dear bot and MAUI community:
It's pretty obvious (and very easy to repro), what is to do here. The fact that s/needs-repro was assigned to this bug implicates that some of you guys don't read on the job. I don't have time for this. I was trying to be y good developer by reporting a bug. Be my guest and close the issue if it makes happy, I'm not wasting anymore time on this.

@PureWeen
Copy link
Member

PureWeen commented Nov 3, 2023

@StephaneDelcroix thoughts?

@PureWeen PureWeen added this to the Backlog milestone Nov 3, 2023
@PureWeen PureWeen removed the s/needs-attention Issue has more information and needs another look label Nov 3, 2023
@ghost
Copy link

ghost commented Nov 3, 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.

@StephaneDelcroix
Copy link
Contributor

@mattleibow and the doc were right. but I did a change to allow x:Type extension there to support what we support in runtime XAML but weren't in compiled one

StephaneDelcroix added a commit that referenced this issue Nov 7, 2023
rmarinho added a commit that referenced this issue Jan 29, 2024
* Add Obsolete tag for old IndexOf (#20068)

* Split the InputTransparency tests (#19925)

* Bump Xamarin.UITest to 4.3.4 (#20067)

* Bump Xamarin.UITest to 4.3.4

* Update NUnit

* Restore dotnet tool (#20106)

* Do not use underscores in the ApplicationId (#19377)

* Do not use underscores in the ApplicationId

Underscores are not supported on Windows

* Update DotnetInternal.cs

* [WinUI] Add workaround for Connectivity check on Win10  (#19261)

* Implemented a Win10 work-around for connectivity thread issue

Reimplement `ConnectivityImplementation.ConnectionProfiles` to use native .net core APIs

* Remove prop bag ID

* Replace network availability changed event with native .net API

* Remove explicit file include

* Fix file naming

* Implemented a Win10 work-around for connectivity thread issue

Reimplement `ConnectivityImplementation.ConnectionProfiles` to use native .net core APIs

* Remove prop bag ID

* Replace network availability changed event with native .net API

* Remove explicit file include

* Fix file naming

* * Revert change to remove `Windows.Networking.Connectivity.NetworkInformation.NetworkStatusChanged`

* Update Connectivity.uwp.cs

---------

Co-authored-by: Mike Corsaro <mikecorsaro@microsoft.com>
Co-authored-by: Matthew Leibowitz <mattleibow@live.com>

* [Windows] Adjust recycle check in ItemContentControl (#20079)

* Adjust recycle check in `ItemContentControl` to use Content property

* Fix confusing line

* Rectify the scopes in the builder (#19932)

* Update System.Drawing.Common (#20122)

* Enable building WASDK Self-Contained packaged apps (#20019)

* Translucent and Transparent NavigationBar on iOS (#19204)

* Changes for enabling translucent navigation bar ios

* Add UITest for NavigationPage Safe Area Translucence

* remove UIKit

* Move UITest from gallery to Issues

* push a new page for UITests, consolidate code, and save shadowimage

* Changes for enabling translucent navigation bar ios

* Add UITest for NavigationPage Safe Area Translucence

* remove UIKit

* Move UITest from gallery to Issues

* make the extension method

* use the background color alpha for translucent

* use same alpha logic for pre ios 15

* accidently added testing comments

* add more UITests for the different NavigationPage and Flyout Page scenarios

* use additionalsafeareainsets for the secondary toolbar

* missing new line

* only run the secondary toolbar offset when we have a secondary toolbar

* use existing childViewControllers

* remove the shadow stuff and simplify the expression with null

* style and fixes from merge conflicts

* standardAppearance and scrolledgeappearance should be kept in

* changes after talking with Shane

* change shell behavior to be more like navrenderer with preiOS13

* move code if we are transparent pre13 shell

* remove new lines

* add screenshot tests

* be able to remove and add secondarybar additionalsafeareas

* reset the xaml on the Sandboc MainPage (#20082)

* [Android] Fix gif animation initial state (#14295)

* Fix gifs initial animation state on Android

* Device tests

* Auto-format source code

* Updated sample

* Updated device tests

* Refactor code

* Update src/Core/src/Handlers/Image/ImageHandler.Android.cs

Co-authored-by: Matthew Leibowitz <mattleibow@live.com>

* Remove unnecessary change

* Fix build errors

* Merge branch 'main' into fix-7019

* Fix merge mistake

---------

Co-authored-by: GitHub Actions Autoformatter <autoformat@example.com>
Co-authored-by: Javier Suárez <6755973+jsuarezruiz@users.noreply.github.com>
Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
Co-authored-by: Gerald Versluis <gerald.versluis@microsoft.com>

* Enable Windows Image device tests (#20167)

* [X] allow x:Type extension for BPConverter (#18540)

- fixes #18324

* Source Generator Performance Improvements (#19990)

* Source Generator Performance Improvements:
- Reversed lookup order (Extension second)
- Introduced type cache

```
PERF PROGRESS:
SourceGen - Maui.Controls.Sample (262 XAML files)

1) Unchanged:
- 15640 GetTypeByMetadata calls
- 223s

2) Extensions lookup in XmlTypeXamlExtensions.GetTypeReference() second
- 6232 GetTypeByMetadata calls (~60% reduction)
- 90s                          (~60% reduction)

3) With type cache
- 203 GetTypeByMetadata calls (~97% reduction => ~99% total reduction)
- 6s                          (~93% reduction => ~97% total reduction => 37 times faster!)
```

* - Set uinitial lookupNames capacity to 2 since there won't be more than 2

* Added appium UITest for FlyoutNavigationBetweenItemsWithNavigationStacks (#19444) Fixes #16675

* Add better exception for missing Maps on Windows (#19046)

* Add better exception for missing Maps on Windows

* Update AppHostBuilderExtensions.cs

* [ci] Add missing demands (#20183)

* Add comments to internal methods for XAML Hot Reload usage (#20215)

* Add comments to internal methods for XAML Hot Reload usage

* spacing

* Adding Mobile tag to MAUI project templates (#20191)

Co-authored-by: Luke Westendorf <lukewest@microsoft.com>

---------

Co-authored-by: Tim Miller <drasticactions@users.noreply.github.com>
Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
Co-authored-by: Gerald Versluis <gerald.versluis@microsoft.com>
Co-authored-by: Mike Corsaro <corsarom@gmail.com>
Co-authored-by: Mike Corsaro <mikecorsaro@microsoft.com>
Co-authored-by: TJ Lambert <50846373+tj-devel709@users.noreply.github.com>
Co-authored-by: Javier Suárez <javiersuarezruiz@hotmail.com>
Co-authored-by: GitHub Actions Autoformatter <autoformat@example.com>
Co-authored-by: Javier Suárez <6755973+jsuarezruiz@users.noreply.github.com>
Co-authored-by: Stephane Delcroix <stephane@delcroix.org>
Co-authored-by: Marco Goertz <mgoertz@microsoft.com>
Co-authored-by: MSLukeWest <42553283+MSLukeWest@users.noreply.github.com>
Co-authored-by: Luke Westendorf <lukewest@microsoft.com>
@github-actions github-actions bot locked and limited conversation to collaborators Mar 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants