使用RadioButtons对ComboBox进行排序 [英] sort ComboBox with RadioButtons

查看:84
本文介绍了使用RadioButtons对ComboBox进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的第一个排序过程在"InitializeComponent()"之后,可以很好地工作,并对我的ComboBox中的项目进行排序;但是,其他两个完全相同的命令本应用来关闭RadioButton的命令却无法完成任务. (逐步执行该程序表示 IF语句已被访问.)在此先感谢您的任何建议.我真的更愿意在XAML中完成所有这些工作,因此,对此计数的任何建议也将不胜感激.

The first sort procedure below, after "InitializeComponent()", works just fine and sorts the items in my ComboBox; however, the other two identical commands which are supposed to key off the RadioButtons don't do the job. (Stepping through the program indicates that the IF statements are visited.) Thanks in advance for any suggestions. I would really prefer to do this all in XAML, so any suggestions on that count would also be appreciated.

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        cboCust.Items.SortDescriptions.Add(new SortDescription("CompanyName", ListSortDirection.Ascending));
    }

    private void rad_Select(object sender, RoutedEventArgs e)
    {
        RadioButton rad = sender as RadioButton;
        if (rad.Name.Contains("Des"))
        cboCust.Items.SortDescriptions.Add(new SortDescription("CompanyName", ListSortDirection.Descending));
        else
            if (rad.Name.Contains("Asc"))
                cboCust.Items.SortDescriptions.Add(new SortDescription("CompanyName", ListSortDirection.Ascending));
    }

}


推荐答案

您要添加冲突的排序描述.在添加新的描述集合之前,请先清除其描述集合.

you're adding conflicting sort descriptions. Clear the description collection before you add a new one.

致谢

Yoni


这篇关于使用RadioButtons对ComboBox进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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