0

Im currently working on an Application that uses WPF and OpenGL. Since Airspace is not a satisfying option for my project, I decided to go with WPF rendered to a Bitmap. Now im stuck with getting events executed. So far i was able to create a function to walk the VisualTree for the needed UIElements but i cant find any information on how to execute theire events.

       public static void MouseClickEventHandler(bool isleftbutton,int mouseX,int mouseY)
    {
        if(self == null)
        {
            return;
        }
        PointHitTestParameters p = new PointHitTestParameters(new Point(mouseX, mouseY));
        VisualTreeHelper.HitTest(self,  new HitTestFilterCallback(delegate(DependencyObject o)
            {

                return HitTestFilterBehavior.Continue;
             }),
             new HitTestResultCallback(delegate(HitTestResult r)
             {

                 UIElement el = r.VisualHit as UIElement;
                 while(true)
                 {
                     if(el != null)
                     {
                         if(el.Focusable && (el is FrameworkElement))
                         {

                             if(isleftbutton)
                             {
                                 Type t = el.GetType();
                                 MemberInfo[] mem = t.GetMembers(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                                 Object locker = new Object();
                                 bool clickable = false;

                                 Parallel.ForEach(mem, delegate(MemberInfo member)
                                 {
                                     if(member.Name.ToLower().Contains("click"))
                                     {
                                         lock(locker)
                                         {
                                             clickable = true;
                                         }

                                     }
                                 });
                                 if(clickable)
                                 {
                                     //launch click event

                                     Console.WriteLine("mouseClick:" + (el as FrameworkElement).Name);

                                     return HitTestResultBehavior.Stop;

                                 }
                             }
                             else
                             {
                                 Console.WriteLine("mouseOver:" + (el as FrameworkElement).Name);
                                 //launch mouse over event

                                 return HitTestResultBehavior.Stop;
                             }

                         }

                         el = (UIElement)VisualTreeHelper.GetParent(el);
                     }
                     else
                     {
                         break;
                     }
                 }

                 return HitTestResultBehavior.Continue;
             }), p);



    }
Alex
  • 711
  • 6
  • 12

1 Answers1

0
RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left)
{
  RoutedEvent = Mouse.MouseDownEvent,
  Source = this,
});

Answered here and here:

Raising WPF MouseLeftButtonDownEvent event

http://alala666888.wordpress.com/2010/07/15/raise-event-manually-in-wpf/

Community
  • 1
  • 1
Colin Smith
  • 12,375
  • 4
  • 39
  • 47