예제 #1
0
        private void PART_ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            FlushTextBox();
            var listBox = sender as ListBox;
            var items   = listBox.SelectedItems;

            if (items.Count <= 0)
            {
                return;
            }
            var          type    = FlagEnumObject.GetType();
            Int64        te      = 0;
            List <Int64> selects = new List <Int64>();

            foreach (var item in items)
            {
                var data = item as EnumData;
                if (data.Checked)
                {
                    var value = System.Convert.ToInt64(System.Enum.Parse(FlagEnumObject.GetType(), data.TextStr));
                    te |= value;
                    selects.Add(value);
                }
            }
            FlagEnumObject = System.Enum.ToObject(type, te);
            OnChangedValue?.Invoke(FlagEnumObject, selects.ToArray());
        }
예제 #2
0
        private void userControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (FlagEnumObject == null)
            {
                return;
            }
            var objType       = FlagEnumObject.GetType();
            var newType       = EngineNS.CEngine.Instance.MacrossDataManager.MacrossScripAssembly.GetType(objType.FullName);
            int flagEnumValue = (int)FlagEnumObject;

            if (newType == null)
            {
                newType = objType;
            }
            if ((newType != null && newType != objType) || EnumList.Count == 0)
            {
                EnumList.Clear();
                var values = System.Enum.GetValues(newType);
                foreach (var value in values)
                {
                    var data    = new EnumData();
                    var nameStr = System.Enum.GetName(newType, value);
                    data.TextStr = nameStr;
                    if ((flagEnumValue & (int)value) == (int)value)
                    {
                        data.Checked = true;
                    }
                    else
                    {
                        data.Checked = false;
                    }
                    EnumList.Add(data);
                }
                //FlagEnumObject = System.Enum.ToObject(newType, flagEnumValue);
                FlushTextBox();
            }
        }