Event that fires when a Pivot Grid Cells have completed rendering

3 posts, 1 answers
  1. Ernie S
    Ernie S avatar
    33 posts
    Member since:
    Apr 2014

    Posted 02 Sep 2014 Link to this post

    I would like to wire the left click of all Pivot Grid cells to perform something using a Behavior<RadPivotGrid>.  So basically what I have here:

    01.private void WireCells()
    02.{
    03.    var textblocks = AssociatedObject.ChildrenOfType<TextBlock>();
    04. 
    05.    if (textblocks == null || !textblocks.Any())
    06.        return;
    07. 
    08.    var tbsWithCellData = textblocks.Where(tb => tb.DataContext is CellData);
    09.    tbsWithCellData.ForEach(t =>
    10.    {
    11.        t.MouseLeftButtonDown -= OnCellMouseLeftButtonDown;
    12.        t.MouseLeftButtonDown += OnCellMouseLeftButtonDown;
    13.    });
    14.}


    So far, the only place I have been able to find that will perform the call so it works is using the Layout
    1.protected override void OnAttached()
    2.{
    3.    base.OnAttached();
    4.    AssociatedObject.LayoutUpdated += AssociatedObject_OnLayoutUpdated;
    5.}

    Again, this is via a Behavior.  But the above is fired almost constantly since that event is fired any time, for example, the mouse moves over the control.

    I tried using the DataProvider.StatusChanged event and waiting for it to be Ready but the cells are not yet rendered there either.  What event could I wire that guarantees the TextBlocks are all rendered  and ready to be wired?

    Thanks
    Ernie
  2. Ernie S
    Ernie S avatar
    33 posts
    Member since:
    Apr 2014

    Posted 03 Sep 2014 in reply to Ernie S Link to this post

    UPDATE.

    Ok, figured out a butter way to wire it up using EventToCommandBehavior object:

    protected override void OnAttached()
    {
        base.OnAttached();
     
        ClickCommand = new DelegateCommand<object>(OnCellClick);
     
        var eb = new EventBinding
        {
            EventName = "MouseLeftButtonUp",
            PassEventArgsToCommand = true,
            Command = ClickCommand
        };
     
        var ebs = EventToCommandBehavior.GetEventBindings(AssociatedObject);
        ebs.Add(eb);
     
    }

    This is definitely better but is this the best?

    THanks
    Ernie
  3. DevCraft banner
  4. Answer
    Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 04 Sep 2014 Link to this post

    Hello Ernie,

    There's no event that can guarantee you that all Cells are rendered. The approach with EventBinding seems fine, so you can use it in your project.

    Feel free to contact us in case you have any problems or concerns.

    Regards,
    Rosen Vladimirov
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top