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

binding isexpanded

2 Answers 223 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
David Ocasio asked on 29 Apr 2016, 09:52 PM

I want whenever an item is added for it to start expanded.

My treeview is bound to a viewmodel.

I am using code examples from the forums to bind the isexpanded to a viewmodel isexpanded property like below.

The code worked for a bit and then recently stopped . the treeview does not render at all if the style is applied. if I remove the style it works fine.

Any ideas. is there a simpler way to do it .

Any help would be appreciated.

 

<Style TargetType="{x:Type telerik:RadTreeViewItem}" x:Key="Cola"  >
    <Setter Property="IsSelected" Value="{Binding Path=IsSelected,Mode=TwoWay}"  />
    <Setter Property="IsExpanded" Value="{Binding Path=IsExpanded,Mode=TwoWay}"/>
</Style>

<telerik:RadTreeView Grid.Row="0" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  Margin="4"
                       SelectedItem="{Binding SelectedTreeViewModel,Mode=TwoWay}" ItemContainerStyle="{StaticResource Cola}"
                       ItemsSource="{Binding TreeViewModels}"  >
      <telerik:RadTreeView.ItemTemplate>
          <HierarchicalDataTemplate ItemsSource="{Binding TreeViewModels}"  >
              <StackPanel Orientation="Horizontal" >
                  <Image Source="{Binding Image}" Height="16" Width="16" VerticalAlignment="Center"  />
                  <TextBlock Text="{Binding Name}" Margin="4,0,0,0" VerticalAlignment="Center" />
              </StackPanel>
          </HierarchicalDataTemplate>
      </telerik:RadTreeView.ItemTemplate>
  </telerik:RadTreeView>

2 Answers, 1 is accepted

Sort by
0
Accepted
Dinko
Telerik team
answered on 04 May 2016, 01:49 PM
Hello David Ocasio,

This behavior is expected if you are using NoXaml binaries in your application. Looking at the provided code snippet the BasedOn property is not set on your custom styles. When working with our NoXaml binaries and Implicit Styles you need to have in mind that your custom Styles that target our controls should be based on their default styles. You can do this by setting the BasedOn property of the custom Style. You can find more information in our Setting a Theme article.
<Style TargetType="{x:Type telerik:RadTreeViewItem}"  BasedOn="{StaticResource RadTreeViewItemStyle}">
    <Setter Property="IsSelected" Value="{Binding Path=IsSelected,Mode=TwoWay}"  />
    <Setter Property="IsExpanded" Value="{Binding Path=IsExpanded,Mode=TwoWay}"/>
</Style>

Please, give this approach a try and If you still encounter this issues you can send us a sample runnable version of your project attached as an archive in this thread. This way we'll be able to inspect it locally and provide you with more information on the case.

Regards,
Dinko
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 04 May 2016, 04:05 PM

Dinko,

Thanks very much. That worked. Knew it had to be something simple.

Thanks

David Charles Ocasio

 

Tags
TreeView
Asked by
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
Answers by
Dinko
Telerik team
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
Share this question
or