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

dynamic RadDiagramToolboxGroupStyle selector

2 Answers 90 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 25 Sep 2017, 04:47 PM

Hello,

I am looking to dynamically set the RadDiagramToolboxGroupStyle based on a style or template selector. I found this : http://www.telerik.com/forums/radwrappanel-instead-of-raduniformgrid-in-raddiagramtoolbox   which does work to set the /default/ style of a RadDiagramToolboxGroup created in the application. However, I don't want to change every instance, just a single one, in a single specific situation. If I add x:Key to my style, what do I change in the definition of the RadDiagramToolbox to implement using that new toolbox group style? (better yet, is there a style or template selector I can use to dynamically set that?)

I've tried the SelectedContentTemplate but I can't seem to get that to work

I've tried ItemContainerStyleSelector that didn't work

I've tried ItemContainerStyle inside the HierarchicalDataTemplate applied to the raddiagramtoolbox.ItemTemplate and that also didn't work

 

Any advice?

2 Answers, 1 is accepted

Sort by
0
Adam
Top achievements
Rank 1
answered on 25 Sep 2017, 07:34 PM

I figured this out. Posting to help anyone else that might have this same requirement. It turns out that RadDiagramToolbox.ItemContainerStyleSelector is the correct place to do this. When I tired that before I was met with exceptions applying my selected style. The reason was that the SelectStyle method of the StyleSelector was passed NOT only RadDiagramToolboxGroup but also RadDiagramToolboxItem too!

My created style worked great for RadDiagramToolboxGroup but would fail when applied to RadDiagramToolboxItem. I do not know why the ItemContainerStyleSelector is being passed the individual items that will eventually live in the container. That doesn’t make sense and might be a bug? But the solution was straightforward. Inside the SelectStyle method simply look at the type of the provided property called container. If that type is a RadDiagramToolboxGroup pass back a style that fits it. If not, pass back nothing or the base.SelectStyle value.

I wish I would have put a breakpoint inside this method a long time ago to understand exactly why my style wasn’t working. I just assumed that only the RadDiagramToolboxGroup items would run though this style selector, not each individual tool box item.

I would recommend considering evaluating that as a bug. Or if there is a valid reason for this behavior please let me know.

0
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 28 Sep 2017, 02:09 PM
Adam,

This is expected behavior and comes from the framework. Let me try to explain. The RadDiagramToolbox derives from HeaderedItemsControl class. So when you are using ItemContainerStyleSelector a style will be applied to each generated container element. In your case, the group and its corresponding group Items are generated when you run the application. 

I have isolated this behavior using the Microsoft TreeView. The TreeViewItem derives from HeaderedItemsControl class. In the CustomStyleSelector class, you can observe the same behavior. First, the SelectStyle method will be called for the parent groups (CustomGroup) then will be fired for children of the groups (CustomGroupItem).

Also in the attached project if you set the IsExpanded property to False of the parent the sub items will not be generated and the SelectStyle() method of the CustomStyleSelector will not be called.

Hope this information is helpful.

Regards,
Dinko
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
Diagram
Asked by
Adam
Top achievements
Rank 1
Answers by
Adam
Top achievements
Rank 1
Dinko | Tech Support Engineer
Telerik team
Share this question
or