【问题标题】:Telerik RADListBox with CheckBox - How to trigger a checked item in checkbox to call its RADListBox SelectedValue eventTelerik RADListBox with CheckBox - 如何触发复选框中的选中项以调用其 RADListBox SelectedValue 事件
【发布时间】:2016-03-28 21:17:07
【问题描述】:

我在使用 RadListBox 并检查复选框中的项目时遇到了 UI 问题。问题是我在复选框中的选择不会触发事件,因为它在触发它的 RADListBox 中的选择。并且用户需要勾选Checkbox然后选择(点击)radlistbox中的项目来触发它的SelectedValue事件。我想拥有它,以便当用户选中复选框时,也会调用 RadListBox 的 Selectedvalue 事件。这是我的 WPF 代码:

<telerik:RadListBox  Grid.Row="1" x:Name="ExportersList" ItemsSource="{Binding Exporters}" Style="{StaticResource ModalListBoxStyle}"
           Visibility="{Binding ExportComplete, Converter={StaticResource InverseBoolToVisibilityConverter}}"
           SelectedValue="{Binding ExportFormatName, Mode=TwoWay}" SelectedValuePath="Name" SelectionMode="Multiple">
            <telerik:RadListBox.ItemTemplate>
                <DataTemplate DataType="{x:Type interfaces:BaseTourSheetExporterType}">
                    <StackPanel Orientation="Horizontal">
                        <CheckBox IsChecked="{Binding IsExporterChecked}" />
                        <TextBlock Text="{Binding Name}"  Margin="5" />
                    </StackPanel>
                </DataTemplate>
            </telerik:RadListBox.ItemTemplate>
        </telerik:RadListBox>

请注意,SelectedValue 事件绑定到我的类中的一个属性,当它获取/设置时,我正在启用/禁用另一个按钮。我不知道如何让我的 Checkbox IsChecked 事件(当用户选中或取消选中复选框时)触发 radlistbox 的 selectedvalue 事件,并且基本上允许我的用户只选中/取消选中触发另一个 get/set 属性的复选框(导出格式名称)。因此,通过这种方式,用户无需在 radlistbox 中再次选择该项目(在复选框外部单击)即可触发该获取/设置属性事件。请帮助我完成这个 WPF 部分。

除此之外,我特意将 CheckBox IsChecked 绑定到一个名为 BaseTourSheetExporterType 的类,该类持有一个成员布尔值 (IsExporterChecked)。这决定了它是否被选中(当我重新打开窗口时,这个类和成员需要记住我的更改)。

【问题讨论】:

  • 我认为瑞秋的回答会对你有所帮助。 stackoverflow.com/questions/23295857/…
  • @AyyappanSubramanian 这已经部分解决了这个问题,我使用了 Rachel 的代码和发布问题的用户的代码,但我发现另一件事丢失了......请看我的回答
  • 尝试将 Mode = TwoWay 添加到绑定中。还要检查你是否实现了 INotifyPropertyChanged。

标签: c# wpf checkbox selectedvalue telerik-radlistbox


【解决方案1】:

我现在通过修改复选框的 onclick 事件解决了这个问题。这是函数的更新版本(请注意最后一行),我在其中强制调用 selectedvalue 和我的 RadListBox:

private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
    {
        var cb = sender as CheckBox;
        if (cb == null)
        {
            return;
        }

        var item = cb.DataContext;
        this.ExportersList.SelectedItem = item;
        this.ExportersList.SelectedValue = this.ExportersList.SelectedItem.GetType().GetProperty("Name").GetValue(this.ExportersList.SelectedItem, null);
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多