I need to access the OnOff property in a Switch within the ListView.GroupHeaderTemplate this property is in the collection used by ListView.ItemTemplate, I have tried in many ways without success, has anyone ever had this problem?
>
<ListView
ItemsSource="{Binding ItemsGrouped}"
GroupShortNameBinding="{Binding Key}"
IsGroupingEnabled="true"
GroupDisplayBinding="{Binding Key}"
x:Name="ListViewAllDevices">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell.View>
<StackLayout>
<Label Text="{Binding Title}"/>
<Label Text="{Binding Description}"/>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout>
<Label Text="{Binding Key}" />
<Switch IsToggled="{Binding OnOff, Source={x:Reference Name=ListViewAllDevices}}"/>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
I think you may to change the viewModel .Each groupHeaderTemplate can bind one value. My code as below:
Model
ItemSource
XMAL
PS: Once you
setListView.GroupHeaderTemplate
,ListView.GroupDisplayBinding
will set to null automatically, so you don't need to setListView.GroupDisplayBinding
, but don't forgetIsGroupingEnabled="true"