Пример #1
0
        private void OnArrangeElements(Canvas canvas)
        {
            foreach (var item in DisplayDERs.ToList())
            {
                for (int i = 1; i < 13; i++)
                {
                    Canvas canvas1 = (Canvas)(MainCanvas).Children[i];
                    if (canvas1.Resources["taken"] == null)
                    {
                        BitmapImage logo = new BitmapImage();
                        logo.BeginInit();
                        logo.UriSource = new Uri("pack://application:,,," + item.ImageSource, UriKind.RelativeOrAbsolute);
                        logo.EndInit();

                        canvas1.Background = new ImageBrush(logo);
                        canvas1.Resources.Add("taken", true);
                        ((TextBlock)(canvas1).Children[0]).Text       = item.Name;
                        ((TextBlock)(canvas1).Children[0]).Foreground = Brushes.White;
                        ((TextBlock)(canvas1).Children[1]).Text       = item.Id.ToString();
                        ((TextBlock)(canvas1).Children[1]).Foreground = Brushes.Transparent;

                        DisplayDERs.Remove(DisplayDERs.FirstOrDefault(x => x.Id == item.Id));

                        break;
                    }
                }
            }
        }
Пример #2
0
        private void OnMainCanvasLoaded(Canvas canvas)
        {
            if (MainCanvas.Children.Count == 0)
            {
                MainCanvas = canvas;
            }
            else
            {
                for (int i = 1; i < 13; i++)
                {
                    Canvas showCanvas  = (Canvas)canvas.Children[i];
                    Canvas savedCanvas = (Canvas)MainCanvas.Children[i];

                    showCanvas.Background = savedCanvas.Background;
                    showCanvas.Resources  = savedCanvas.Resources;
                    ((TextBlock)(showCanvas).Children[0]).Text       = ((TextBlock)(savedCanvas).Children[0]).Text;
                    ((TextBlock)(showCanvas).Children[0]).Foreground = ((TextBlock)(savedCanvas).Children[0]).Foreground;
                    ((TextBlock)(showCanvas).Children[1]).Text       = ((TextBlock)(savedCanvas).Children[1]).Text;
                    ((TextBlock)(showCanvas).Children[1]).Foreground = ((TextBlock)(savedCanvas).Children[1]).Foreground;

                    if (!string.IsNullOrEmpty(((TextBlock)(showCanvas).Children[1]).Text))
                    {
                        DisplayDERs.Remove(DisplayDERs.FirstOrDefault(x => x.Id == int.Parse(((TextBlock)showCanvas.Children[1]).Text)));
                    }
                }
                MainCanvas = canvas;
            }
        }
Пример #3
0
        private void OnDrop(Canvas canvas)
        {
            if (SelectedDisplayDER != null)
            {
                if (canvas.Resources["taken"] == null)
                {
                    BitmapImage logo = new BitmapImage();
                    logo.BeginInit();
                    logo.UriSource = new Uri("pack://application:,,," + SelectedDisplayDER.ImageSource, UriKind.RelativeOrAbsolute);
                    logo.EndInit();

                    canvas.Background = new ImageBrush(logo);
                    canvas.Resources.Add("taken", true);
                    ((TextBlock)(canvas).Children[0]).Text       = SelectedDisplayDER.Name;
                    ((TextBlock)(canvas).Children[0]).Foreground = Brushes.White;
                    ((TextBlock)(canvas).Children[1]).Text       = SelectedDisplayDER.Id.ToString();
                    ((TextBlock)(canvas).Children[1]).Foreground = Brushes.Transparent;

                    tempName = SelectedDisplayDER.Name;

                    DisplayDERs.Remove(DisplayDERs.FirstOrDefault(x => x.Id == SelectedDisplayDER.Id));
                    SelectedDisplayDER = null;
                }
                ((TextBlock)(canvas).Children[0]).Text       = tempName;
                ((TextBlock)(canvas).Children[0]).Foreground = Brushes.White;
                dragging = false;
            }
        }