zoukankan      html  css  js  c++  java
  • Syncfusion 复选框 ComboBoxAdv

        XAML:

        

     <syncfusion:GridTemplateColumn.EditTemplate>
                                                <DataTemplate DataType="viewModel:CustomerViewModel" >
                                                    <syncfusion:ComboBoxAdv ItemsSource="{x:Static viewModel:RecordStatusModel.RecordStatusItem}" DropDownOpened="ComboBoxAdvStatus_DropDownOpened" DropDownClosed="ComboBoxAdvStatus_DropDownClosed"
                                                    AllowMultiSelect="True">
    </syncfusion:ComboBoxAdv> </DataTemplate> </syncfusion:GridTemplateColumn.EditTemplate>

       1。绑定数据源。一个静态的List<string>即可。

       2.关键的两个事件:DropDownOpened和DropDownClosed。 即打开和关闭。在复选框打开的时候初始化,关闭的时候处理用户的选择。

      

      /// <summary>
            /// 报警级别复选框
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void ComboBoxAdvStatus_DropDownOpened(object sender, EventArgs e)
            {
                var cbatmp = (ComboBoxAdv)sender;
                var alarmtypeselect = new ObservableCollection<object>();
                var targetuser = CustomersDatagrid.SelectedItem as CustomerViewModel;
                if (targetuser != null)
                {
                    var liststr = RecordStatusModel.AlarmStatusToStrList(targetuser.RecordTypeFlags);
                    foreach (var str in liststr)
                    {
                        alarmtypeselect.Add(str);
                    }
                    cbatmp.SelectedItems = alarmtypeselect;
                }
            }
    
            /// <summary>
            /// 报警类型复选框
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void ComboBoxAdvStatus_DropDownClosed(object sender, EventArgs e)
            {
                ComboBoxAdv cbatmp = (ComboBoxAdv)sender;
                var tmp = cbatmp.SelectedItems.ToList<string>();
                var targetuser = CustomersDatagrid.SelectedItem as CustomerViewModel;
                var flag = RecordStatusModel.AlarmStrListToEnum(tmp);
                if (targetuser != null) targetuser.RecordTypeFlags = flag;
                alarmHandleViewModel.Save();
            }
    RecordStatusModel:
    static class RecordStatusModel
        {
           private static List<string> _recordStatusItem;
           private static Dictionary<AlarmStatusFlags, string> _alarmStatusDictionary;
    
           public static List<string> RecordStatusItem
           {
               get { return _recordStatusItem??(_recordStatusItem=new List<string>()
               {
                    "报警",
                    "应答",
                    "恢复",
                    "移除",
               }); }
           }
    
           public static Dictionary<AlarmStatusFlags, string> AlarmStatusDictionary
           {
               get
               {
                   return _alarmStatusDictionary ?? (_alarmStatusDictionary = new Dictionary<AlarmStatusFlags, string>()
                   {
                    {AlarmStatusFlags.Alarm, "报警"},
                    {AlarmStatusFlags.Acked, "应答"},
                    {AlarmStatusFlags.Recover, "恢复"},
                    {AlarmStatusFlags.Remove, "移除"},
                   });
               }
           }
    
           public static List<string> AlarmStatusToStrList(AlarmStatusFlags flags)
           {
               return (from dic in AlarmStatusDictionary where (int)(dic.Key & flags) > 0 select dic.Value).ToList();
           }
    
           public static AlarmStatusFlags AlarmStrListToEnum(IEnumerable<string> list)
           {
               return (from str in list from dic in AlarmStatusDictionary where dic.Value == str select dic)
                   .Aggregate<KeyValuePair<AlarmStatusFlags, string>, AlarmStatusFlags>(0, (current, dic) => current | dic.Key);
           }
        }
    View Code
  • 相关阅读:
    洛谷 P7520
    Involuting Bunny! (2021.8)
    Solution -「Gym 102979E」Expected Distance
    Solution -「Gym 102979L」 Lights On The Road
    Solution -「CodeChef JUMP」Jump Mission
    Solution -「洛谷 P4372」Out of Sorts P
    Solution -「Gym 102956F」Find the XOR
    Solution -「Gym 102956B」Beautiful Sequence Unraveling
    Solution -「Gym 102956F」Border Similarity Undertaking
    Solution -「LOJ #6029」「雅礼集训 2017」市场
  • 原文地址:https://www.cnblogs.com/stoneniqiu/p/4105587.html
Copyright © 2011-2022 走看看