I have a Xamarin forms project and I created a layout with an ItemsSource
and an ItemTemplate
property.
I bind a list to my itemsSource and then the layout create the items based on the itemTemplate.
Everything works fine except I would like to get the right intellisense suggestion when I create the ItemTemplate
. I would like to spectify that the BindingContext
of my ItemTemplate
is of type T
if my ItemsSource is List<T>
.
I don't know how I can specify this in my code. Do you have an y suggestion or at least some google keywords?
Thanks a lot!
<ListView x:Name="ListViewName">
</ListView>
And then call it in Xaml.cs:
public class ClassName
{
public ClassName()
{
var control = ListViewName;
}
}
If I understand you correctly, You are asking to bind MVVM binding properties in XAML file. Try this, Say your page name is HomePage
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="DataBinding101.HomePage">
<StackLayout Padding="0,20,0,0">
<StackLayout Padding="0,20,0,0" Orientation="Horizontal">
<Label Text="Your forename is:" />
<Label Text="{Binding Forename}" />
</StackLayout>
<StackLayout Orientation="Horizontal">
<Label Text="Your surname is:" />
<Label Text="{Binding Surname}" />
</StackLayout>
</StackLayout>
</ContentPage>
Homepage.xaml.cs
public partial class HomePage : ContentPage
{
public HomePage ()
{
InitializeComponent ();
BindingContext = new DetailsViewModel ();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.