binding isexpanded

3 posts, 1 answers
  1. David Ocasio
    David Ocasio avatar
    147 posts
    Member since:
    Nov 2009

    Posted 29 Apr Link to this post

    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. Answer
    Dinko
    Admin
    Dinko avatar
    204 posts

    Posted 04 May Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. David Ocasio
    David Ocasio avatar
    147 posts
    Member since:
    Nov 2009

    Posted 04 May in reply to Dinko Link to this post

    Dinko,

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

    Thanks

    David Charles Ocasio

     

Back to Top