Пример #1
0
 private void RefreshSelection()
 {
     SelectionOptions.Clear();
     SelectionOptions.Add("--All Cons Together--");
     foreach (var con in ComicCons.Select(c => c.EventName).Distinct())
     {
         SelectionOptions.Add(con.ToString());
     }
 }
Пример #2
0
        public override void FromXML(XmlNode vNode)
        {
            base.FromXML(vNode);

            SelectionOptions.Clear();
            XmlNodeList oNodes = vNode.ChildNodes;

            foreach (XmlNode oNode in oNodes)
            {
                ItemSelectorOption option = null;
                try
                {
                    switch (oNode.LocalName)
                    {
                    case "Text":
                        string labelText = oNode.Attributes.GetNamedItem("text").Value;

                        option = new ItemSelectorLabel {
                            Label = labelText
                        };
                        break;

                    case "Image":
                        string imageLocation = Path.Combine(OverlaySettings.Instance.Location.Directory.FullName,
                                                            oNode.Attributes.GetNamedItem("image").Value);

                        option = new ItemSelectorImage {
                            Location = imageLocation
                        };
                        break;

                    case "Color":
                        string colorValue = oNode.Attributes.GetNamedItem("color").Value;
                        if (ColorConverter.ConvertFromString(colorValue) == null)
                        {
                            throw new InvalidXMLValueException("OverlayItemSelector:Option", "color", InvalidXMLValueException.Reason.InvalidValue);
                        }

                        option = new ItemSelectorColor {
                            Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(colorValue))
                        };
                        break;
                    }
                } catch (Exception) {
                    throw new InvalidXMLValueException("OverlayItemSelector:Option", oNode.LocalName, InvalidXMLValueException.Reason.NotSpecified);
                }

                if (option == null)
                {
                    throw new InvalidXMLValueException("OverlayItemSelector:Option", oNode.LocalName, InvalidXMLValueException.Reason.InvalidValue);
                }


                foreach (XmlAttribute xAttrib in oNode.Attributes)
                {
                    switch (xAttrib.LocalName)
                    {
                    case "value":
                        option.Value = xAttrib.Value;
                        break;

                    case "alt":
                        option.Alt = xAttrib.Value;
                        break;
                    }
                }

                option.PropertyChanged += new PropertyChangedEventHandler(ItemSelectorOption_PropertyChanged);
                SelectionOptions.Add(option);
            }

            RaisePropertyChanged("Columns");

            foreach (XmlAttribute vNodeAttrib in vNode.Attributes)
            {
                try
                {
                    switch (vNodeAttrib.LocalName)
                    {
                    case "default":
                        DefaultValue = vNodeAttrib.Value;
                        break;

                    case "value":
                        Value = vNodeAttrib.Value;
                        break;

                    case "columns":
                        Columns = int.Parse(vNodeAttrib.Value);
                        break;

                    case "itemHeight":
                        ItemHeight = double.Parse(vNodeAttrib.Value);
                        break;

                    case "itemWidth":
                        ItemWidth = double.Parse(vNodeAttrib.Value);
                        break;
                    }
                } catch (FormatException) {
                    throw new InvalidXMLValueException("OverlayItemSelector", vNodeAttrib.Value, InvalidXMLValueException.Reason.FormatIncorrect);
                } catch (ArgumentNullException) {
                    throw new InvalidXMLValueException("OverlayItemSelector", vNodeAttrib.Value, InvalidXMLValueException.Reason.NotSpecified);
                } catch (OverflowException) {
                    throw new InvalidXMLValueException("OverlayItemSelector", vNodeAttrib.Value, InvalidXMLValueException.Reason.Overflow);
                }
            }

            if (DefaultValue == null && SelectionOptions.Count > 0)
            {
                DefaultValue = SelectionOptions.First().Value;
            }
        }