private void canvasCreated(Dogadjaj d)
        {
            BitmapImage logo  = new BitmapImage();
            Dugme       dugme = new Dugme();

            dugme.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(button_selected);
            dugme.Width           = 40;
            dugme.Height          = 40;
            dugme.Focusable       = false;
            dugme.Tag             = d;
            dugme.ToolTip         = "Oznaka: " + d.oznaka + ", Naziv: " + d.naziv;
            dugme.BorderBrush     = Brushes.Black;
            dugme.BorderThickness = new Thickness(2);

            double maxX = canvas123.Width - dugme.Width;
            double maxY = canvas123.Height - dugme.Height;


            if (initialized == false)
            {
                for (int i = 1; i < listaDog.Count; i++)
                {
                    listaDog.ElementAt(i).Y = listaDog.ElementAt(i - 1).Y + 45 / maxY;
                }

                initialized = true;
            }

            foreach (Dogadjaj dog in listaDog)
            {
                if (dog.oznaka != d.oznaka && d.X == dog.X && d.Y == dog.Y)
                {
                    d.Y = dog.Y + 45 / maxY;
                    break;
                }
            }

            Canvas.SetLeft(dugme, d.X * maxX);
            Canvas.SetTop(dugme, d.Y * maxY);

            canvas123.Children.Add(dugme);

            try
            {
                logo.BeginInit();
                logo.UriSource   = new Uri(d.ikonica);
                logo.CacheOption = BitmapCacheOption.OnLoad;
                logo.EndInit();
                ImageBrush img = new ImageBrush(logo);
                img.Stretch      = Stretch.UniformToFill;
                dugme.Background = img;
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e.StackTrace);
            }
        }
 private void button_selected(object sender, MouseButtonEventArgs e)
 {
     if (!dragging)
     {
         dragging    = true;
         draggedItem = (Dugme)sender;
         DragDrop.DoDragDrop(this, draggedItem, DragDropEffects.Move);
         e.Handled = true;
     }
 }
        private void Canvas_Drop(object sender, DragEventArgs e)
        {
            base.OnDrop(e);
            if (draggedItem != null)
            {
                double maxX = canvas123.Width - 65;
                double maxY = canvas123.Height - 65;
                Point  p    = e.GetPosition(canvas123);

                if ((p.Y + 32.5 <= canvas123.Height && p.Y - 32.5 >= 0) && (p.X + 32.5 <= canvas123.Width && p.X - 32.5 >= 0))
                {
                    foreach (Dogadjaj d in listaDog)
                    {
                        if (d == draggedItem.Tag)
                        {
                            foreach (Dogadjaj d1 in listaDog)
                            {
                                if (d1 != d)
                                {
                                    if (Math.Round(d1.X, 1) == Math.Round(d.X, 1) && Math.Round(d1.Y, 1) == Math.Round(d.Y, 1))
                                    {
                                        if (d.X == d1.X && d.Y == d1.Y)
                                        {
                                            d.X = d1.X + 25 / maxX;
                                            break;
                                        }
                                        else if (d.X < d1.X && d.Y < d1.Y)
                                        {
                                            d.X = d1.X - 25 / maxX;
                                            d.Y = d1.Y - 25 / maxY;
                                            break;
                                        }
                                        else if (d.X > d1.X && d.Y < d1.Y)
                                        {
                                            d.X = d1.X + 25 / maxX;
                                            d.Y = d1.Y - 25 / maxY;
                                            break;
                                        }
                                        else if (d.X > d1.X && d.Y > d1.Y)
                                        {
                                            d.X = d1.X + 25 / maxX;
                                            d.Y = d1.Y + 25 / maxY;
                                            break;
                                        }
                                        else
                                        {
                                            d.X = d1.X - 25 / maxX;
                                            d.Y = d1.Y + 25 / maxY;
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        d.X = (p.X - 32.5) / maxX;
                                        d.Y = (p.Y - 32.5) / maxY;
                                    }
                                }
                            }
                        }
                    }
                }

                canvas123.Children.Clear();

                foreach (Dogadjaj d in listaDog)
                {
                    canvasCreated(d);
                }

                draggedItem = null;
                dragging    = false;
            }
            e.Handled = true;
        }