请帮帮我我是Xamarin表单的新手,我想绑定到ICollection(Navigation Property)的属性。我试过很多方法它没有用,例如我试过我需要这样做工作任何帮助将不胜感激。我正在使用MVVM帮助器和James Montemagno分组并使用棱镜 如何绑定到导航属性? 感谢
Public Class Category{
public int ID {get;set;}
public string CatName {get;set;}
public virtual ICollection<Item> items {get;set;}
}
Public Class Item{
public Id {get;set;}
public Catname{get;set;}
public ItemName {get;set;}
Public virtual <SubItems> SubItems {get;set;}
}
Public Class SubItem{
public Id {get;set;}
public ItemName{get;set;}
public SubItemName {get;set;}
}
Public Class Expandable : BaseViewMdoel{
public Catagory CataGory{ get;set;}
public bool IsSelected {get;set;}
}
Public Class ExpandableListView : BaseViewModel{
public ObservableRangeCollection<Catagory> CollectionOfCatagory { get; } =
new ObservableRangeCollection<Catagory>();
public ObservableCollection<Grouping<Expandable ,Catagory>>SelectedCatagroy
{ get; set; } = new ObservableCollection<Grouping<Expandable, Catagory>>();
public DelegateCommand<Grouping<Expandable,Catagory>> HeaderCommand
{get
{
return new DelegateCommand<Grouping<Expandable , Catagory>>(g =>
{
if (g == null) return;
g.Key.IsSelected = !g.Key.IsSelected;
if (g.Key.IsSelected )
{
foreach (var item in CollectionOfCatagory )
{
var m = item.Catagory.Where(i => i.ID ==
g.Key.Catagory.ID);
foreach (var x in m)
{
g.Add(item);
}
}
}
else
{
g.Clear();
}
});
}
}
Void GroupListOfItem(){
var items = CollectionOfCatagory.Select(
x => new Expandable{ Catagory = x, IsSelected = false }
).GroupBy(c => new { c.Catagory.CatName}).Select(g =>
g.First()).ToList();
items.ForEach(c => SelectedCatagroy.Add(new
Grouping<Expandable, Catagory>(c, new
ObservableRangeCollection<Catagory>())));
}
}
我的观点:
<ListView ItemsSource="{Binding CollectionOfCatagory }"
IsGroupingEnabled="True">
<ListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell>
<ContentView Padding="10,0,0,0">
<Label Text="{Binding Key.Catagory.CatName}"
VerticalOptions="Center"/>
<ContentView.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Source=
{x:Reference CatagoryListPage},
Path=BindingContext.HeaderCommand}" CommandParameter="
{Binding .}" />
</ContentView.GestureRecognizers>
</ContentView>
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="10,0,0,0">
<StackLayout Orientation="Horizontal">
<StackLayout WidthRequest="40">
<Label Text="{Binding Catname}" />
</StackLayout>
<Label Text = {Binding How To bind to properties of
navigation Please help}
</StackLayout>
<Image Source="Cat1"/>
</StackLayout>
</StackLayout>
</ViewCell>