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

ItemContainerStyle Causing Telerik radTreeview to disappear. (WPF)

6 Answers 129 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jawad
Top achievements
Rank 1
Jawad asked on 11 Jul 2013, 12:33 PM

Hi,
the application is based on MVVM using Prism with MEF.
I have converted  windows tree view control to Telerik RadTreeview control. everything worked fine except that the ItemContainerStyle defined is somehow disabling the tree to be shown.  if I remove the ItemContainerStyle from the Radtreeview the tree becomes visible but with not styling.
 by using the windows treeview with same ItemcontainerStyle work fine.
Following is the code.

<uxc:UxtWindow.Resources>
 <HierarchicalDataTemplate x:Key="SiteWizardTemplate" 
                                  ItemsSource="{Binding Steps}" >
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding DisplayAs}" />
            </StackPanel>
        </HierarchicalDataTemplate>
    </uxc:UxtWindow.Resources>
  
 <telerik:RadTreeView  IsVirtualizing="True"
                         ItemsSource="{Binding Wizard.WizardSections}" 
                          ItemTemplate="{StaticResource SiteWizardTemplate}"                                          
                               PreviewMouseDown="TreeView_PreviewMouseDown" >
                            
                               <telerik:RadTreeView.ItemContainerStyle>
                                <Style TargetType="{x:Type telerik:RadTreeViewItem}">
                                    <Setter Property="FontSize" Value="18" />
                                    <Setter Property="FontStyle" Value="Italic" />
                                    <Setter Property="Margin" Value="0,5,0,10" />
                                    <Setter Property="Foreground" Value="Black" />
                    </telerik:RadTreeView.ItemContainerStyle>
                      
                            
</telerik:RadTreeView>

6 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 16 Jul 2013, 09:01 AM
Hi Jawad,

Unfortunately I was not able to reproduce this issue. However, I feel there might be something I'm missing from your implementation. Can you please have a look at the attached solution and let me know if it works for you. Also, if it doesn't properly describes your scenario, can you try to modify it to better demonstrate your case and reproduce the described issue. This will allow us to locally investigate it and suggest a solution.

Thank you in advance for your cooperation on the mater.

Regards,
Tina Stancheva
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Jawad
Top achievements
Rank 1
answered on 22 Jul 2013, 02:25 PM
by adding BasedOn Property on the Style fixed the issue. 

<Style x:Key="MainStepStyle" TargetType="{x:Type telerik:RadTreeViewItem}" BasedOn="{StaticResource RadTreeViewItemStyle}">
0
Thomas
Top achievements
Rank 2
answered on 02 Feb 2014, 08:45 PM
Just wanted to confirm that this also solved my issue, so thank you for posting this. Took me a while to figure this out.

I believe this is only an issue when you are using implicit styles. In my case, when I switched the Telerik.Windows.Controls.Navigation assembly (which contains the RadTreeView) to the NoXaml version used for implicit styling, this issue came up. When I switched back to the all-including Xaml version, the issue disappeared. However, this is typically not what you want, if you have decided to use implicit styles. So we really need to get to the root of this issue.

Here's my attempt at an explanation: In the documentation, including the BasedOn property is the approach explained. Using BasedOn is what you need to do in order to "override" a style that has already been defined by the Telerik team, and included in the Theme Xaml DLL you're using.

In the case above, you want to modify the RadTreeViewItem style by just setting the properties you want to override. In order to do that, you must include the BasedOn property, otherwise you would have to include all properties of the RadTreeViewItem.

In my case, I wanted to bind the IsExpanded property of each node in the tree to the matching property of my view model for the tree, and including the BasedOn property also did the trick here.



0
Tina Stancheva
Telerik team
answered on 05 Feb 2014, 01:44 PM
Hi Thomas,

Thanks for jumping in and shedding more light on the issue. Your explanation is absolutely correct and the only thing I want to add to it is a small piece of information regarding the NoXaml assemblies.

As their name suggests, those are assemblies that do not contain any xaml - no style resources or ControlTemplates are applied on the components defined in these assemblies. This is why it is up to you to apply a style on a component referenced from a NoXaml assembly. You can do that by defining a custom style - which means that you will need to also define a ControlTemplate for the component, or by including our default styles. In the second case, if you need to change a few setters you would need to base your custom style on a default style in order to make sure that the default style setters are also applied, specifically so that they can set a ControlTemplate for the component.

Regards,
Tina Stancheva
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Tom
Top achievements
Rank 1
answered on 29 Oct 2017, 11:54 AM
Please update your TreeView documentation to reflect this
0
Martin Ivanov
Telerik team
answered on 01 Nov 2017, 10:41 AM
Hello Tom,

Thank you for the feedback. We have a common article about the BasedOn attribute. However, we will add some information about this also in our RadTreeView documentation.

Regards,
Martin Ivanov
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
TreeView
Asked by
Jawad
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Jawad
Top achievements
Rank 1
Thomas
Top achievements
Rank 2
Tom
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or