1

我在使用 RadListBox 并检查 Checkbox 中的项目时遇到 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)。这决定了它是否被选中(当我重新打开窗口时,这个类和成员需要记住我的更改)。

4

1 回答 1

0

我现在通过修改复选框的 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);
    }
于 2016-03-29T21:37:32.880 回答