dynamic RadDiagramToolboxGroupStyle selector

3 posts, 1 answers
  1. Adam
    Adam avatar
    4 posts
    Member since:
    Aug 2017

    Posted 25 Sep 2017 Link to this post


    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. Adam
    Adam avatar
    4 posts
    Member since:
    Aug 2017

    Posted 25 Sep 2017 Link to this post

    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.

  3. Answer
    Dinko avatar
    523 posts

    Posted 28 Sep 2017 Link to this post

    Hello 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.

    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.
Back to Top