コード例 #1
0
        private void Image_RightClick(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Right)
            {
                Image image = sender as Image;

                string   tooltip   = (string)image.ToolTip;
                string[] elements  = tooltip.Split('\n');
                string   id1       = elements[0];
                string[] elements1 = id1.Split(' ');
                string   id        = elements1[2];
                //Console.WriteLine("ID VRSTE JE:   " + id);
                ContextMenu contextMenu = new ContextMenu();

                MenuItem item1 = new MenuItem();

                item1.Header = "Detalji";

                int indexDetails = 0;

                for (int i = 0; i < ListaVrsta.Count; i++)
                {
                    if (id.Equals(ListaVrsta[i].Id))
                    {
                        indexDetails = i;
                        break;
                    }
                }

                item1.Click += delegate {
                    VrstePrikaz vp = new VrstePrikaz(indexDetails);
                };

                contextMenu.Items.Add(item1);

                MenuItem item2 = new MenuItem();

                item2.Header = "Izmeni";

                Vrsta zaIzmenu = null;

                foreach (Vrsta v in MainWindow.ListaVrsta)
                {
                    if (id.Equals(v.Id))
                    {
                        zaIzmenu = v;
                        break;
                    }
                }
                int indexIzmena = 0;

                for (int i = 0; i < ListaVrsta.Count; i++)
                {
                    if (id.Equals(ListaVrsta[i].Id))
                    {
                        indexIzmena = i;
                        break;
                    }
                }


                item2.Click += delegate {
                    IzmenaVrsta re = new IzmenaVrsta(indexIzmena);
                    image.ToolTip = " ID: " + zaIzmenu.Id + "\n Ime: " + zaIzmenu.Ime + "\n Tip: " + zaIzmenu.Tip + "\n Ime tipa: " + zaIzmenu.Tip.Ime;
                    image.Source  = zaIzmenu.Ikonica;
                };

                contextMenu.Items.Add(item2);

                MenuItem item3 = new MenuItem();

                item3.Header = "Obriši";

                item3.Click += delegate {
                    for (int i = 0; i < DropList.Children.Count; i++)
                    {
                        Image img = (Image)DropList.Children[i];
                        if (img.Equals(image))
                        {
                            DropList.Children.RemoveAt(i);
                            string   text        = img.ToolTip.ToString();
                            string[] prvaPodela  = text.Split('\n'); // " ID: id"
                            string[] drugaPodela = prvaPodela[0].Split(' ');
                            listaZaMapu.Remove(drugaPodela[2]);
                        }
                    }
                };

                contextMenu.Items.Add(item3);

                image.ContextMenu           = contextMenu;
                contextMenu.PlacementTarget = image;
                contextMenu.IsOpen          = true;
            }
        }
コード例 #2
0
 private void MenuItem_Click_3(object sender, RoutedEventArgs e)
 {
     VrstePrikaz vrstePrikaz = new VrstePrikaz();
 }