Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Scrolling + MouseEvent Not Working

$
0
0

The idea is the following: I want to generate a amount of views based on data As you can see in the code, in addition to generate the event mouseExited and mouseEntered. But this crashes.

     //Init controller
     public override void AwakeFromNib()

 {  

            base.AwakeFromNib();
    this.scrollview.HasHorizontalScroller = true;
    this.scrollview.HasVerticalScroller = true;
    this.scrollview.ScrollsDynamically = false;
    panel = new NSView(new RectangleF(0,0
        ,this.scrollview.Frame.Width
        ,this.scrollview.Frame.Height*3));
    float indexer = 5;
    foreach (var name in Data)
    {
        var customData = new CustomData(new RectangleF(5,indexer,this.scrollview.Frame.Width - 5,70))
        {
            Text = name.Key
        };
        indexer += 90;
        customData.MouseEnter += MouseEnterEvent;
        customData.MouseExited += MouseExitedEvent;
        panel.AddSubview(customData);
    }
    this.scrollview.DocumentView = panel;
}
    //Finish Controller


public class CustomData : NSView
{

    public override void DrawRect(RectangleF dirtyRect)
    {
        base.DrawRect(dirtyRect);
        var context = NSGraphicsContext.CurrentContext.GraphicsPort;
        var rectangle = new RectangleF (0,0, this.Frame.Width, this.Frame.Height);
        NSColor.Blue.Set ();
        context.FillRect (rectangle);
                    //Text is a string
        s = new NSString (Text);
                    //attributes is stringAttributes
        s.DrawString (new PointF(20,this.Frame.Height/3), attributes);

    }
    public override void UpdateTrackingAreas()
    {
        if (tracking != null)
        {
            this.RemoveTrackingArea(tracking);
            tracking.Release();
        }
        tracking = new NSTrackingArea(this.Frame,NSTrackingAreaOptions.MouseEnteredAndExited | NSTrackingAreaOptions.ActiveAlways ,this, null);
        this.AddTrackingArea(tracking);
    }

    public override void MouseEnter(NSEvent theEvent)
    {
        Console.WriteLine("MouseEnteredTest");
    }

    public override void MouseExited(NSEvent theEvent)
    {
        Console.WriteLine("MouseExitedTest");
    }
}

Any suggestions will be highly appreciated. Thanks!


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>