Using a Picker control in Xamarin, is it possible to specify x:DataType for the ItemDisplayBinding property that is different than the x:DataType bound to the control itself?

Scott Collins 1 Reputation point
2021-06-13T17:12:02.46+00:00

Using a Picker view, I can specify x:DataType for the control which will use compiled bindings to set the ItemsSource property. However, the entries in the ItemsSource value are not of the same type. I would like to be able to specify the x:DataType for the items so that the ItemDisplayBinding property will use XAML Binding Compilation.

Is there a way to do this?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,334 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Kyle Wang 5,531 Reputation points
    2021-06-14T06:14:40.723+00:00

    Hi ScottCollins-2957,

    Welcome to our Microsoft Q&A platform!

    According to the documentation Xamarin.Forms Compiled Bindings, we know that the x:DataType attribute can only be set on a VisualElement.

    We can re-define the x:DataType at any location in a view hierarchy, such as a control or a DataTemplate. But we cannot set x:DataType for the property of a certain control.

    Regards,
    Kyle


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.