This is a migrated thread and some comments may be shown as answers.

Event that fires when a Pivot Grid Cells have completed rendering

2 Answers 59 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
Ernie S
Top achievements
Rank 1
Ernie S asked on 02 Sep 2014, 06:46 PM
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 Answers, 1 is accepted

Sort by
0
Ernie S
Top achievements
Rank 1
answered on 03 Sep 2014, 03:42 PM
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
0
Accepted
Rosen Vladimirov
Telerik team
answered on 04 Sep 2014, 02:20 PM
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.
 
Tags
PivotGrid
Asked by
Ernie S
Top achievements
Rank 1
Answers by
Ernie S
Top achievements
Rank 1
Rosen Vladimirov
Telerik team
Share this question
or