public OverlayImageView(OverlayImageViewModel viewModel)
        {
            InitializeComponent();
            BindingContext = viewModel;

            //Binding binding = new Binding("Text");
            //binding.Source = trackOpacity;
            //SetBinding(Image, binding);
        }
Esempio n. 2
0
        public void FromXML(XmlNode xOverlayNode)
        {
            try
            {
                foreach (XmlAttribute xAttrib in xOverlayNode.Attributes)
                {
                    try
                    {
                        switch (xAttrib.LocalName)
                        {
                        case "margin":
                            Margin = (Thickness)(new ThicknessConverter()).ConvertFromString(xAttrib.Value);
                            break;

                        case "halign":
                            HorizontalAlign = (HorizontalAlignment)Enum.Parse(typeof(HorizontalAlignment), xAttrib.Value);
                            break;

                        case "valign":
                            VerticalAlign = (VerticalAlignment)Enum.Parse(typeof(VerticalAlignment), xAttrib.Value);
                            break;

                        case "background":
                            Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(xAttrib.Value));
                            break;

                        case "width":
                            Width = double.Parse(xAttrib.Value);
                            break;

                        case "height":
                            Height = double.Parse(xAttrib.Value);
                            break;
                        }
                    } catch (FormatException) {
                        throw new InvalidXMLValueException("Overlay", xAttrib.LocalName, InvalidXMLValueException.Reason.FormatIncorrect);
                    } catch (ArgumentNullException) {
                        throw new InvalidXMLValueException("Overlay", xAttrib.LocalName, InvalidXMLValueException.Reason.NotSpecified);
                    } catch (ArgumentException) {
                        throw new InvalidXMLValueException("Overlay", xAttrib.LocalName, InvalidXMLValueException.Reason.InvalidValue);
                    } catch (OverflowException) {
                        throw new InvalidXMLValueException("Overlay", xAttrib.LocalName, InvalidXMLValueException.Reason.Overflow);
                    } catch (Exception) {
                        throw new InvalidXMLValueException("Overlay", xAttrib.LocalName, InvalidXMLValueException.Reason.InvalidValue);
                    }
                }
            } catch (InvalidXMLValueException ex) {
                MessageBox.Show(ex.Message);
                throw new OverlayCreationException(OverlayCreationException.Reason.InvalidXML);
            }

            foreach (XmlNode xNode in xOverlayNode.ChildNodes)
            {
                OverlayItemBaseModel oi = null;

                switch (xNode.LocalName)
                {
                case "Image":
                    oi = new OverlayImageViewModel();
                    break;

                case "Text":
                    oi = new OverlayTextViewModel();
                    break;

                case "Gradient":
                    oi = new OverlayGradientViewModel();
                    break;
                }

                if (oi != null)
                {
                    try
                    {
                        oi.FromXML(xNode);
                    } catch (InvalidXMLValueException ex) {
                        MessageBox.Show(ex.Message);
                        throw new OverlayCreationException(OverlayCreationException.Reason.InvalidXML);
                    }
                    OverlayItems.Add(oi);
                }
            }
        }