C#WPF检查所有复选框 [英] C# WPF check all checkboxes

查看:64
本文介绍了C#WPF检查所有复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



在一个表格中,我生成几个带有装订的按钮。



XML:



Hello

In a form, i generate several buttons, with binding.

In a XML :

<Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="0.1*" />
            <RowDefinition Height="0.85*" />
            <RowDefinition Height="0.15*" />
        </Grid.RowDefinitions>
        <ItemsControl x:Name="lvDataBinding" HorizontalContentAlignment="Stretch" BorderThickness="0" Margin="10" Grid.Row="1" Background="{x:Null}" ItemsSource="{Binding}" Grid.ColumnSpan="4" Foreground="White">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Border BorderBrush="White" BorderThickness="1" CornerRadius="3" Margin="0,3" Grid.ColumnSpan="0" Background="Transparent" HorizontalAlignment="Left" VerticalAlignment="Top">
                        <StackPanel Orientation="Vertical" >
                            <CheckBox x:Name="cbxLignes" Tag="{Binding strCodeLigne}" Style="{StaticResource {x:Type ToggleButton}}" Content="{Binding strCodeLigne}" FontSize="22" Margin="25,15,25,15" Width="100" Height="45" IsChecked="{Binding IsChecked}" Checked="cbxLignes_Checked" Unchecked="cbxLignes_Unchecked" />
                        </StackPanel>
                    </Border>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
        </ItemsControl>
        <Button Name="btnValider" Grid.Row="4" Grid.Column="2" Content="Valider" Background="#5491fe" Margin="95,5,5,5"  Click="btnValider_Click" />
        <Button Name="btnTous" Grid.Row="4" Grid.Column="0" Content="Tous" Background="#5491fe" Margin="95,5,5,5" Click="btnTous_Click"  />
        <Button Name="btnAucuns" Grid.Row="4" Grid.Column="1" Content="Aucun" Background="#5491fe" Margin="5,5,95,5"  />
        <Button Name="btnAnnuler" Grid.Row="4" Grid.Column="3" Content="Annuler" Background="#5491fe" Margin="5,5,95,5" Click="btnAnnuler_Click"  />
    </Grid>





我的绑定是用SQL值生成的:





My binding is generate with SQL values :

for (int i = 0; i < dvLignes.Count; i++)
            {
                clLignes = new CL_Lignes();

                //clLignes.strIDLigne = dvLignes[i]["IDLigne"].ToString().Trim();
                clLignes.strCodeLigne = dvLignes[i]["CodeLigne"].ToString().Trim();
                //clLignes.strDesLigne = dvLignes[i]["DesLigne"].ToString().Trim();

                lstLignes.Add(clLignes);

                this.DataContext = lstLignes;
            }





我需要一个按钮,选中所有复选框生成。我事先并不知道文字按钮是如何以及产生的那样。



提前谢谢。



我尝试了什么:



我试图找到一个循环,但我没有找到



I need with a button, check all checkboxes generate. I don't know in advance how and which text buttons has generate

Thank you in advance.

What I have tried:

I try to find a loop, but i don't found

推荐答案

因此,您有一个集合,其中包含一个名为IsChecked的布尔值作为其属性之一。首先,确保IsChecked的编写方式使其引发PropertyChanged事件。然后,遍历您的集合并设置IsChecked = true,以检查它们。绑定引擎将检测被触发的PropertyChanged事件,并将根据需要更新屏幕上的值。
So, you have a collection that contains, as one of its properties, a boolean called IsChecked. First of all, make sure that IsChecked is written in such a way that it raises the PropertyChanged event. Then, loop over your collection and set IsChecked = true, to check them. The binding engine will detect the PropertyChanged event being fired, and will update the value on screen as appropriate.


这篇关于C#WPF检查所有复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆