Esempio n. 1
0
        private void ButtonClick(object sender, RoutedEventArgs e)
        {
            var main   = Owner as MainWindow;
            var name   = Sub + "_" + xName.Content + "x" + yName.Content;
            var button = (Button)main.FindName(name);

            if (button != null)
            {
                button.Background = new SolidColorBrush(xColor.SelectedColor);
                button.Foreground = new SolidColorBrush(xColorFont.SelectedColor);
                button.Content    = xCaption.Text;

                var elm = button.Tag as ClassGridGroup.Elm ?? new ClassGridGroup.Elm(
                    RepositoryXmlFile.GetPathByType(XmlDocEnum.B),
                    (byte)X,
                    (byte)Y,
                    button.Content.ToString(),
                    GetSelected(xGBFunction));

                elm.Func       = GetSelected(xGBFunction);
                elm.Background = button.Background;
                elm.Foreground = button.Foreground;
                elm.Caption    = button.Content.ToString();
                if (elm.Caption == string.Empty)
                {
                    ProductType product;
                    elm.Caption    = FunctionsTranslateService.GetTranslatedFunctionWithProd(elm.Func, out product);
                    button.Content = elm.Caption;
                }

                button.Tag = elm;

                var bReset = (Button)sender;
                if (bReset.Tag.ToString() == "Réinitialiser la configuration")
                {
                    button.Tag = "None - Vide";
                }

                if (button.Tag != null && button.Tag.ToString() == "None - Vide")
                {
                    button.ClearValue(BackgroundProperty);
                    button.Content = string.Empty;
                    button.ToolTip = Properties.Resources.LabelNone;
                }
                ClassGridGroup.Save(button);
                Close();
            }
        }
Esempio n. 2
0
        public static Elm[,] Load(XmlDocEnum type, int payId = -1)
        {
            var g       = new Elm[12, 12];
            var xmlGrid = RepositoryXmlFile.Load(type, payId);

            var xId         = (from el in xmlGrid.Elements("Grid").Elements("rec").Elements("id") select el).ToList();
            var xX          = (from el in xmlGrid.Elements("Grid").Elements("rec").Elements("X") select el).ToList();
            var xY          = (from el in xmlGrid.Elements("Grid").Elements("rec").Elements("Y") select el).ToList();
            var xCaption    = (from el in xmlGrid.Elements("Grid").Elements("rec").Elements("Caption") select el).ToList();
            var xColor      = (from el in xmlGrid.Elements("Grid").Elements("rec").Elements("Color") select el).ToList();
            var xImg        = (from el in xmlGrid.Elements("Grid").Elements("rec").Elements("Img") select el).ToList();
            var xFunc       = (from el in xmlGrid.Elements("Grid").Elements("rec").Elements("Fun") select el).ToList();
            var xForeground = (from el in xmlGrid.Elements("Grid").Elements("rec").Elements("foreground") select el).ToList();

            for (var i = 0; i < xId.Count; i++)
            {
                var f = new Elm(RepositoryXmlFile.GetPathByType(type, payId), xX[i].Value.ToByte(), xY[i].Value.ToByte(), xCaption[i].Value, xFunc[i].Value);

                var argbtColor      = xColor[i].Value.Split(',');
                var argbtForeground = xForeground.Count != xId.Count ? new[] { "255", "255", "255", "255" } : xForeground[i].Value.Split(',');

                if (argbtColor.Length == 0)
                {
                    f.Background = null;
                }

                if (argbtColor.Length == 4)
                {
                    f.Background =
                        new SolidColorBrush(Color.FromArgb(byte.Parse(argbtColor[0]), byte.Parse(argbtColor[1]), byte.Parse(argbtColor[2]), byte.Parse(argbtColor[3])));
                }

                if (argbtColor.Length == 3)
                {
                    f.Background = new SolidColorBrush(Color.FromRgb(byte.Parse(argbtColor[0]), byte.Parse(argbtColor[1]), byte.Parse(argbtColor[2])));
                }

                if (argbtForeground.Length == 0)
                {
                    f.Foreground = null;
                }

                if (argbtForeground.Length == 4)
                {
                    f.Foreground =
                        new SolidColorBrush(Color.FromArgb(byte.Parse(argbtForeground[0]), byte.Parse(argbtForeground[1]), byte.Parse(argbtForeground[2]),
                                                           byte.Parse(argbtForeground[3])));
                }

                if (argbtForeground.Length == 3)
                {
                    f.Foreground = new SolidColorBrush(Color.FromRgb(byte.Parse(argbtForeground[0]), byte.Parse(argbtForeground[1]), byte.Parse(argbtForeground[2])));
                }

                var myImage3 = new Image();
                var bi3      = new BitmapImage();
                bi3.BeginInit();
                bi3.UriSource = new Uri(xImg[i].Value, UriKind.Relative);
                bi3.EndInit();
                myImage3.Stretch = Stretch.Fill;
                myImage3.Source  = bi3;

                f.Img = myImage3;

                g[f.X, f.Y] = f;
            }
            return(g);
        }