Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Xamarin:带有复选框的ListView组标题_C#_Xamarin_Xamarin.android_Syncfusion - Fatal编程技术网

C# Xamarin:带有复选框的ListView组标题

C# Xamarin:带有复选框的ListView组标题,c#,xamarin,xamarin.android,syncfusion,C#,Xamarin,Xamarin.android,Syncfusion,在应用程序中,我有一个绑定到某些数据的ListView,并且它已被分组。我需要在group header中设置一个复选框,一旦选中group header复选框,则必须选择组下面的所有数据。我在分组标题中添加了一个复选框,如 <xFormsListView:SfListView x:Name="SpecialityDiseaseListView" itemsSource="{Binding SuggestionDiseaseList}"

在应用程序中,我有一个绑定到某些数据的ListView,并且它已被分组。我需要在group header中设置一个复选框,一旦选中group header复选框,则必须选择组下面的所有数据。我在分组标题中添加了一个复选框,如

<xFormsListView:SfListView x:Name="SpecialityDiseaseListView"
                           itemsSource="{Binding SuggestionDiseaseList}" 
                           ItemSize="40" SelectionBackgroundColor="Transparent">
<xFormsListView:SfListView.DataSource>
    <dataSource:DataSource>
        <dataSource:DataSource.GroupDescriptors>
            <dataSource:GroupDescriptor PropertyName="GroupHeading"/>
        </dataSource:DataSource.GroupDescriptors>
    </dataSource:DataSource>
</xFormsListView:SfListView.DataSource>
<xFormsListView:SfListView.GroupHeaderTemplate>
    <DataTemplate>
        <ViewCell>
            <ViewCell.View>
                <StackLayout Padding="10,0,15,0">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="70*"/>
                            <ColumnDefinition Width="20*"/>
                            <ColumnDefinition Width="10*"/>
                        </Grid.ColumnDefinitions>
                        <Label Text="{Binding Key}"  FontSize="18" 
                               VerticalOptions="Center" HorizontalOptions="Start" 
                               Style="{StaticResource LabelProfileStyle}"/>
                        <buttons:SfCheckBox HorizontalOptions="End" Grid.Column="1" 
                                            IsChecked="{Binding IsSelected}"/>
                    </Grid>
                    <BoxView  HeightRequest=".5" BackgroundColor="Black" 
                              HorizontalOptions="FillAndExpand" />                                                               

                </StackLayout>
            </ViewCell.View>
        </ViewCell>
    </DataTemplate>
</xFormsListView:SfListView.GroupHeaderTemplate>
<xFormsListView:SfListView.ItemTemplate>
    <DataTemplate>
        <ViewCell>
            <StackLayout Orientation="Horizontal" VerticalOptions="FillAndExpand"
                                                             Padding="5,0,0,0" BackgroundColor="Transparent">
                <buttons:SfCheckBox Text="{Binding DisplayName}" IsChecked="{Binding IsSelected, Mode=TwoWay}" Style="{StaticResource ProfileCheckBoxStyle}"></buttons:SfCheckBox>
            </StackLayout>
        </ViewCell>
    </DataTemplate>
</xFormsListView:SfListView.ItemTemplate>

我想做一个小组头球检查,我可以达到预期的能力。有没有人能建议一下我如何实施这一点。
提前感谢。

我会使用
收藏视图
选择模式
多个

<CollectionView SelectionMode="Multiple" SelectedItems="{Binding SelectedItems}">
    <xFormsListView:SfListView.GroupHeaderTemplate>
        <DataTemplate>
            <StackLayout Padding="10,0,15,0">
                <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="70*"/>
                    <ColumnDefinition Width="20*"/>
                    <ColumnDefinition Width="10*"/>
                </Grid.ColumnDefinitions>
                <Label Text="{Binding Key}" FontSize="18" VerticalOptions="Center"
                       HorizontalOptions="Start" Style="{StaticResource LabelProfileStyle}"/>
                <CheckBox Grid.Column="2" IsChecked="{Binding IsChecked}"/>
                </Grid>
                <BoxView HeightRequest=".5" BackgroundColor="Black" 
                                 HorizontalOptions="FillAndExpand" />
            </StackLayout>
        </DataTemplate>
    </xFormsListView:SfListView.GroupHeaderTemplate>
</CollectionView>

视图模型:

public ObservableCollection<object> SelectedItems { get; set; } = new ObservableCollection<object>();
公共ObservableCollection SelectedItems{get;set;}=new ObservableCollection();
SelectedItems
属性的类型必须是
observeableCollection
,否则它将无法工作。Xamarin.Forms 4.6中提供了对自定义对象的支持,但目前尚不存在。然后用户可以选择他们想要的项目,或者您可以使用复选框以编程方式将项目放入
SelectedItems


扩展
复选框
以接受字符串,这样您就可以传递组名并知道要在
SelectedItems
中放置哪些项

您可以参考以下文档以使用SfListView GroupHeader中的复选框,

在本例中,我没有看到任何复选框?请在组标题模板中设置代码正确添加预期复选框的格式