Posts Tagged ‘Interaction’
22
Sep

Floatable Window Drag and Drop

Post a comment » Popularity: 1%

Michael Washington enhanced Tim Heuer’s Floatable Window with drag and drop feature.

Silverlight-3-Drag-and-Drop

View Demo: New Window
21
Sep

Hit Test (Get all objects in a specific point)

Post a comment » Popularity: 1%

Most of the time, when you are creating games, you will have to find out all the UIElemetn in a specific coordinate. (Or we can this hittest). In such circumstance, you will need to use the method VisualTreeHelper.FindElementsInHostCoordinates. Please view the C# coding for more details.

Hit-Test

Get all the UIElement in a specific coordinate:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;

namespace HitTest
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            App.Current.RootVisual.MouseLeftButtonDown += new MouseButtonEventHandler(RootVisual_MouseLeftButtonDown);
        }

        void RootVisual_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            List<uielement> list = VisualTreeHelper.FindElementsInHostCoordinates
            (e.GetPosition(null), LayoutRoot as UIElement) as List<uielement>;

            var selectedControls = from control in list
                                   where control is Rectangle
                                   select control as Rectangle;

            if (selectedControls.Count() &gt; 0)
            {
                foreach (var selectedControl in selectedControls)
                {
                    // do your opreation here
                }
            }
        }
    }
}