private void Button_Click(object sender, RoutedEventArgs e) { // Check if Boo is right of Kevin var theRightStuff = RelativePanel.GetRightOf(Stuart); // We'll check for Boo, not Kevin // The first call this returns the string "Kevin", only later it returns the Image "Kevin". // Historic C# // if (theRightStuff is Image && ((String)((Image)theRightStuff).Tag) == "Boo") // // New C# if ((theRightStuff as Image)?.Tag?.ToString() == "Boo") { // Remove Boo RelativePanel.SetRightOf(Stuart, Kevin); MinionPanel.Children.Remove((UIElement)theRightStuff); } else { // Insert Boo var boo = new Image() { Source = new BitmapImage(new Uri("ms-appx:/Assets/Boo.png")), Width = 300, Tag = "Boo" }; // Prepare Boo RelativePanel.SetRightOf(boo, Kevin); RelativePanel.SetAlignBottomWith(boo, Kevin); // Add Boo MinionPanel.Children.Add(boo); // Link to Stuart // Don't do this - it does not draw Boo (Stuart still has RightOf Kevin): // RelativePanel.SetLeftOf(boo, Stuart); // Override the graph edge: RelativePanel.SetRightOf(Stuart, boo); } }