maui
maui copied to clipboard
OnIdiom not working when using as style resource
Description
Currently migrating from XF to Maui, I have multiple pages/views where I defined OnIdiom as resource like so:
<Grid.Resources>
<OnIdiom x:Key="LayoutGridColumnWidth" x:TypeArguments="GridLength" Default="0.25*" Phone="0.33*" />
</Grid.Resources>
Im using those resources multiple times, like this:
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource LayoutGridColumnWidth}" />
</Grid.ColumnDefinitions>
I get the following error:
XFC0009 No property, BindableProperty, or event found for "Default", or mismatching type between value and property. Futura.IA.Models.Views D:\...\AddressView.xaml
The same code is working fine for my Xamarin.Forms Project. I can workaround the issue by not using the StaticResource extension and replace the Style with OnIdiom Markup like this:
<ColumnDefinition Width="{OnIdiom Default=0.25*, Phone=0.33*}" />
Is this working as intended? If yes I have to change a lot of views
Steps to Reproduce
Add a new Page or Control and use OnIdiom as Style Resource as mentioned above or compile the sample repo.
Link to public reproduction project repository
https://github.com/nschoenberg/OnIdiomRepro
Version with bug
6.0.486 (current)
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android, Windows, macOS
Affected platform versions
Windows 11
Did you find any workaround?
Yes, using OnIdiom as markup extension directly instead of static resource
Relevant log output
No response
@StephaneDelcroix thoughts? Should we add this to OnIdiom
?
One additional note: It is working fine when OnIdiom is used as resource when using x:Int32 as type, like so:
<OnIdiom x:Key="ZipCodeRow" x:TypeArguments="x:Int32" Default="1" Phone="2" />
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
Verified this issue with Visual Studio Enterprise 17.7.0 Preview 1.0. Can repro on android platform with above project.
https://github.com/nschoenberg/OnIdiomRepro
The GridLength
struct seems to be missing the TypeConverterAttribute
:
namespace Microsoft.Maui
{
/// <include file="../../docs/Microsoft.Maui/GridLength.xml" path="Type[@FullName='Microsoft.Maui.GridLength']/Docs/*" />
[DebuggerDisplay("{Value}.{GridUnitType}")]
[System.ComponentModel.TypeConverter(typeof(GridLengthTypeConverter))] // <--- This line is missing
public readonly struct GridLength
{
//...
}
}
GridLengthTypeConverter
might have to be moved to \src\Core\src\Converters\
folder in order to be referenced by GridLength
, not sure of the impact of such change.
In the meantime, declaring the <OnIdiom>
values explicitly using their actual type instead of using type conversion will bypass the issue :
<Grid.Resources>
<OnIdiom x:Key="LayoutGridColumnWidth" x:TypeArguments="GridLength">
<OnIdiom.Default>
<GridLength>0.25*</GridLength>
</OnIdiom.Default>
<OnIdiom.Phone>
<GridLength>0.33*</GridLength>
</OnIdiom.Phone>
</OnIdiom>
</Grid.Resources>