Wpf 如何在checbox Checked事件中选择telerik combox中的所有复选框?

Wpf 如何在checbox Checked事件中选择telerik combox中的所有复选框?,wpf,Wpf,我在telerik combo控件中有一个复选框。如果用户单击复选框列表中的所有选项,则我希望选择所有复选框。 复选框值。 我的示例代码如下 <telerik:RadComboBox Name="rcbDays" Grid.Row="1" Grid.Column="1" Width="200" HorizontalAlignment="Left" ItemsSource="{Binding MonthDaysList}" VerticalAlignment="Center" >

我在telerik combo控件中有一个复选框。如果用户单击复选框列表中的所有选项,则我希望选择所有复选框。 复选框值。 我的示例代码如下

<telerik:RadComboBox  Name="rcbDays" Grid.Row="1" Grid.Column="1" Width="200" HorizontalAlignment="Left" ItemsSource="{Binding  MonthDaysList}"  VerticalAlignment="Center" >
       <telerik:RadComboBox.ItemTemplate>
           <DataTemplate>
               <StackPanel Orientation="Horizontal">
                  <CheckBox Name="chkDays" Content="{Binding DaysText}"
           Tag="{Binding DaysValue}" Checked="chkDays_Checked" />
                </StackPanel>
            </DataTemplate>
       </telerik:RadComboBox.ItemTemplate>
</telerik:RadComboBox>

将ComboBox绑定到的项应具有类似IsSelected的属性,然后应将数据模板复选框的IsChecked绑定到该属性。然后您只需要迭代源集合,并在所有项上设置IsSelected=true

e、 g

当然,该物业需要有一个完整的设计


还有一个关于可用性的注意事项:我不认为组合框应该包含复选框,如果您需要多个项目选择,请使用列表框,您需要按照H.B.的说法选择一个属性。 将IsChecked={Binding IsSelected}添加到xaml文件中的复选框标记。在适当的类别中创建一个属性,即public bool iseleted

当您进入此函数中选中的事件chkWeeks_时,获取ComboBox项源的引用,如objList=TypeCastYourClassTypeYourComboBox.ItemSource;。。。现在,objList包含所有复选框项。迭代objList集合并获取每个项目的isSeleted属性,就这样完成了。。。。 就你而言

MonthDayList = (TypeCastYourClassType)rcbDays.ItemSource;
for(int i=0;i<MonthDayList.Count;i++)
{
    MonthDayList[i].isSelected = true;
}

下面是关于允许在telerik组合框中选择多个值的一些很好的讨论。 它在combobox中使用复选框


谢谢:

请阅读。我已将“绑定”复选框绑定到combobox,combobox的属性为IsSelected。@user1228382:我正在谈论绑定项。我是wpf新手,因此我无法理解您的观点。对不起,你能再澄清一下吗。
public class MyClass : MyBaseClass // Whatever you may have called it,
{
     public bool IsSelected { ... }
     public string DaysText { ... }
     //...
}
   <DataTemplate>
       <StackPanel Orientation="Horizontal">
          <CheckBox IsChecked="{Binding IsSelected}" Content="{Binding DaysText}" Tag="{Binding DaysValue}" />
        </StackPanel>
   </DataTemplate>
//In the handler that is supposed to select all
foreach (var item in MonthDaysList) item.IsSelected = true;
MonthDayList = (TypeCastYourClassType)rcbDays.ItemSource;
for(int i=0;i<MonthDayList.Count;i++)
{
    MonthDayList[i].isSelected = true;
}