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

GetClickedElement returns null within a Dispatcher.BeginInvoke code section

5 Answers 62 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Paul Brun
Top achievements
Rank 2
Paul Brun asked on 20 Sep 2011, 08:21 PM
I have a method that renames a tree element. 

private void RenameAction()
{
   if (this.ClickedTreeViewItem != null)
   {
     Dispatcher.BeginInvoke(() =>
     {
       this.ClickedTreeViewItem.BeginEdit();
     });
   }
   else
   {
     Dispatcher.BeginInvoke(() =>
     {
        this.m_SelectedContextEntity.BeginEdit();
     });
   }
}

ClickTreeViewItem is a property in my class that returns the element that is clicked via the "GetClickElement<T>" call.

The check confirms that the clicked element is not null, but the same property within the dispatcher section returns null. The Dispatcher allows us to run the method on the UI Main thread.

Any thoughts on why this would be happening? 
Thanks
Paul

5 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 26 Sep 2011, 09:01 AM
Hello Paul Brun,

Apparently the clicked element is null in the dispatcher because the check is executed in different timeframe than the check in the upper if. You could assign the return value of the function call to a local variable and use that variable for checks and later operations in the method.

Hope this helps. Please let us know if you have further concerns.

Greetings,
Hristo
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Paul Brun
Top achievements
Rank 2
answered on 26 Sep 2011, 12:08 PM
Thanks for the suggestion. I have implemented that, was just curious why it worked in a previous release and not the current one. Or, was it just luck that it worked??? Regards, Paul
0
Petar Mladenov
Telerik team
answered on 29 Sep 2011, 09:41 AM
Hello Paul Brun,

 Probably it is not the release version and it is the inconsistent (due to the asynchronous work) behavior of the Disaptcher. What are the two release versions that you compare?

All the best,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Paul Brun
Top achievements
Rank 2
answered on 29 Sep 2011, 01:04 PM
The two versions of the Telerik Controls I compared were:

2011.2 712 vs. 2010.3 1314

Cheers,
Paul
0
Petar Mladenov
Telerik team
answered on 04 Oct 2011, 09:41 AM
Hi Paul Brun,

 You could also try the Q2 2011 SP1 (0920) version of RadControls but still, we think that it is more like a "Dispatcher-timing" result than a change in the RadTreeView from Q1 SP1 to Q2. Feel free to ask if you have further questions.

Kind regards,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
TreeView
Asked by
Paul Brun
Top achievements
Rank 2
Answers by
Hristo
Telerik team
Paul Brun
Top achievements
Rank 2
Petar Mladenov
Telerik team
Share this question
or