Forum Xamarin.Forms

Using constants for x:Key in ControlTemplate?

MilMil USMember ✭✭

Hello fellow developers

Is it possible to use constants for keys in ControlTemplate?

<ControlTemplate x:Key="FormInputHorizontalTemplate">...</ControlTemplate>

We tried to use something like {x:Static core:Constants.FormInputHorizontalTemplate} but it fails with Exception System.InvalidCastException: 'Unable to cast object of type 'Xamarin.Forms.Xaml.MarkupNode' to type 'Xamarin.Forms.Xaml.ValueNode'.'

The reason for the question is, if we use string identifiers at multiple locations (here as key for the template and then additionally in code) we normally declare them as constants to avoid errors because of renaming.

Thanks in advance!


Sign In or Register to comment.