I am trying to achieve changing background color for my StackLayout based on a trigger that targets enum property.
However I am getting: "An unhandled exception occured".
When I remove the trigger everything works as expected. Here is the relevant code:
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:ParkAndRidePrague"
xmlns:my="clr-namespace:ParkAndRidePrague.Core.Enums;assembly=ParkAndRidePrague.Core"
x:Class="ParkAndRidePrague.MainPage">
<ContentPage.Content>
<ListView x:Name="listViewParkings">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout BackgroundColor="#eee"
Orientation="Vertical">
<StackLayout Orientation="Horizontal">
<Label Margin="10, 5, 0, 5" VerticalTextAlignment="Center" Text="{Binding Name}" TextColor="Black" FontSize="20" />
<Label Margin="0, 5, 10, 5" VerticalTextAlignment="Center" Text="{Binding NumOfFreePlaces}" HorizontalOptions="EndAndExpand" TextColor="Black" FontSize="20" />
<StackLayout.Triggers>
<DataTrigger Binding="{Binding Path=ParkingAvailability}" Value="{x:Static my:ParkingAvailability.Low}">
<Setter Property="BackgroundColor" Value="Red" />
</DataTrigger>
</StackLayout.Triggers>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content> </ContentPage>
Here is the enum:
namespace ParkAndRidePrague.Core.Enums {
public enum ParkingAvailability
{
Low,
Medium,
High
} }
I followed this question/answer but there still seems to be something off that I can't find.
Whole exception:
03-08 11:33:12.511 I/MonoDroid(14705): UNHANDLED EXCEPTION: 03-08 11:33:12.567 I/MonoDroid(14705): Xamarin.Forms.Xaml.XamlParseException: Position 18:38. The Property TargetType is required to create a Xamarin.Forms.DataTrigger object. 03-08 11:33:12.567 I/MonoDroid(14705): at Xamarin.Forms.Xaml.CreateValuesVisitor.Visit (Xamarin.Forms.Xaml.ElementNode node, Xamarin.Forms.Xaml.INode parentNode) [0x0014b] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Xaml\CreateValuesVisitor.cs:77 03-08 11:33:12.568 I/MonoDroid(14705): at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x000b1] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Xaml\XamlNode.cs:176 03-08 11:33:12.568 I/MonoDroid(14705): at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00054] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Xaml\XamlNode.cs:171 03-08 11:33:12.568 I/MonoDroid(14705): at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00089] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Xaml\XamlNode.cs:173 03-08 11:33:12.568 I/MonoDroid(14705): at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00089] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Xaml\XamlNode.cs:173 03-08 11:33:12.568 I/MonoDroid(14705): at Xamarin.Forms.Xaml.ApplyPropertiesVisitor+<>c__DisplayClass32_0.b__0 () [0x0008a] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Xaml\ApplyPropertiesVisitor.cs:474 03-08 11:33:12.568 I/MonoDroid(14705): at Xamarin.Forms.ElementTemplate.CreateContent () [0x00026] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\ElementTemplate.cs:78 03-08 11:33:12.568 I/MonoDroid(14705): at Xamarin.Forms.DataTemplateExtensions.CreateContent (Xamarin.Forms.DataTemplate self, System.Object item, Xamarin.Forms.BindableObject container) [0x00014] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\DataTemplateExtensions.cs:12 03-08 11:33:12.568 I/MonoDroid(14705): at Xamarin.Forms.TemplatedItemsList
2[TView,TItem].CreateContent (System.Int32 index, System.Object item, System.Boolean insert) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\TemplatedItemsList.cs:527 03-08 11:33:12.568 I/MonoDroid(14705): at Xamarin.Forms.TemplatedItemsList
2[TView,TItem].ConvertContent (System.Int32 startingIndex, System.Collections.IList items, System.Boolean forceCreate, System.Boolean setIndex) [0x00014] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\TemplatedItemsList.cs:664 03-08 11:33:12.568 I/MonoDroid(14705): at Xamarin.Forms.TemplatedItemsList2[TView,TItem].OnProxyCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e, System.Boolean fixWindows) [0x0017e] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\TemplatedItemsList.cs:1002 03-08 11:33:12.568 I/MonoDroid(14705): at Xamarin.Forms.TemplatedItemsList
2[TView,TItem].OnProxyCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\TemplatedItemsList.cs:954 03-08 11:33:12.568 I/MonoDroid(14705): at Xamarin.Forms.ListProxy.OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x0000a] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\ListProxy.cs:230 03-08 11:33:12.568 I/MonoDroid(14705): at Xamarin.Forms.ListProxy+<>c__DisplayClass32_0.b__0 () [0x00018] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\ListProxy.cs:203 03-08 11:33:12.568 I/MonoDroid(14705): at Xamarin.Forms.ListProxy.OnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x000a0] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\ListProxy.cs:222 03-08 11:33:12.568 I/MonoDroid(14705): at Xamarin.Forms.ListProxy+WeakNotifyProxy.OnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00031] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\ListProxy.cs:386 03-08 11:33:12.568 I/MonoDroid(14705): at System.Collections.ObjectModel.ObservableCollection1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00012] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/referencesource/System/compmod/system/collections/objectmodel/observablecollection.cs:288 03-08 11:33:12.568 I/MonoDroid(14705): at System.Collections.ObjectModel.ObservableCollection
1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedAction action, System.Object item, System.Int32 index) [0x00000] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/referencesource/System/compmod/system/collections/objectmodel/observablecollection.cs:351 03-08 11:33:12.568 I/MonoDroid(14705): at System.Collections.ObjectModel.ObservableCollection1[T].InsertItem (System.Int32 index, T item) [0x00024] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/referencesource/System/compmod/system/collections/objectmodel/observablecollection.cs:219 03-08 11:33:12.568 I/MonoDroid(14705): at System.Collections.ObjectModel.Collection
1[T].Add (T item) [0x00023] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/referencesource/mscorlib/system/collections/objectmodel/collection.cs:67 03-08 11:33:12.568 I/MonoDroid(14705): at ParkAndRidePrague.MainPage+d__7.MoveNext () [0x00217] in E:\Dev\JakubHolovskyGit\ParkAndRidePrague\ParkAndRidePrague\ParkAndRidePrague\MainPage.xaml.cs:71 03-08 11:33:12.568 I/MonoDroid(14705): --- End of stack trace from previous location where exception was thrown --- 03-08 11:33:12.568 I/MonoDroid(14705): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 03-08 11:33:12.568 I/MonoDroid(14705): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 03-08 11:33:12.568 I/MonoDroid(14705): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 03-08 11:33:12.568 I/MonoDroid(14705): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 03-08 11:33:12.568 I/MonoDroid(14705): at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:113 03-08 11:33:12.568 I/MonoDroid(14705): at ParkAndRidePrague.MainPage+d__4.MoveNext () [0x0002c] in E:\Dev\JakubHolovskyGit\ParkAndRidePrague\ParkAndRidePrague\ParkAndRidePrague\MainPage.xaml.cs:36 03-08 11:33:12.569 I/MonoDroid(14705): --- End of stack trace from previous location where exception was thrown --- 03-08 11:33:12.569 I/MonoDroid(14705): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 03-08 11:33:12.569 I/MonoDroid(14705): at System.Runtime.CompilerServices.AsyncMethodBuilderCore.m__0 (System.Object state) [0x00000] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1018 03-08 11:33:12.569 I/MonoDroid(14705): at Android.App.SyncContext+c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/4009/9578cdcd/source/xamarin-android/src/Mono.Android/Android.App/SyncContext.cs:35 03-08 11:33:12.569 I/MonoDroid(14705): at Java.Lang.Thread+RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/4009/9578cdcd/source/xamarin-android/src/Mono.Android/Java.Lang/Thread.cs:36 03-08 11:33:12.569 I/MonoDroid(14705): at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in /Users/builder/data/lanes/4009/9578cdcd/source/monodroid/src/Mono.Android/platforms/android-25/src/generated/Java.Lang.IRunnable.cs:81 03-08 11:33:12.569 I/MonoDroid(14705): at (wrapper dynamic-method) System.Object:dad7aebb-b573-4058-885d-12720b7c63dd (intptr,intptr)