After updating to latest preview 4.1.0.496342-pre2 from 4.0.0.425677, x:DataType do not allow anything but string, which means {x:Null} is not allowed either. I have to disable compile binding here since the target type is a generic one.
Building without errors.
Complaining "x:DataType expects a string literal".
This was presumably introduced here:
https://github.com/xamarin/Xamarin.Forms/pull/5335
This was presumably introduced here:
5335
However, according to Microsoft Docs introducing to Compiled Binding:
Alternatively, the x:DataType attribute can be re-defined at any point in a view hierarchy to null using the x:Null markup extension.
So {x:Null} is a valid value for x:DataType.
I agree. I wasn't saying the change was correct. The intention was to block {x:Type SomeType}
. I'm now curious whether any other value might be reasonable besides a string or {x:Null}
.
@lekia Can you please attach a small project that demonstrates this issue? Thanks!
Same issue for me when upgrading to XF4.1 (x:DataType expects a string literal
).
This happens when I'm re-defining the data-type, using x:DataType="{x:Null}"
.
Strangely, I'm also having errors with a few valid data types: <DataTemplate x:DataType="{x:Type models:MyModel}">
If I modify this to <DataTemplate x:DataType="models:MyModel">
, it builds, but intellisense does not work anymore for this type.
This is a non-sense. Is there a reason, why you switched to not accepting {x:Type} markup extension? We use it in all other XAML platforms (WPF, WP8, UWP), do you know?
Well regarding {x:Null} issue:
It occurs ONLY if you try to redefine x:DataType inside a DataTemplate:
<StackLayout BindingContext="{Binding ViewModel, Source={x:Reference Root}}">
<ListView>
<ListView.ItemTemplate>
<DataTemplate x:DataType="app3:ViewModel">
<!-- Try to disable compiled binding -->
<Label x:DataType="{x:Null}" Text="{Binding Test}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
Please switch back to accepting {x:Type} as x:DataType.
@samhouts
I'm also seeing this issue. This change has broken a sample/doc, when we've specifically called out the ability to mix compiled bindings with classic bindings by setting x:DataType="{x:Null}"
.
Sample project demoing this error:
Got it! Thanks!
Most helpful comment
This is a non-sense. Is there a reason, why you switched to not accepting {x:Type} markup extension? We use it in all other XAML platforms (WPF, WP8, UWP), do you know?
Well regarding {x:Null} issue:
It occurs ONLY if you try to redefine x:DataType inside a DataTemplate:
Please switch back to accepting {x:Type} as x:DataType.