How to show/hide detail according to binding object

2 posts, 0 answers
  1. Ke
    Ke  avatar
    12 posts
    Member since:
    Sep 2011

    Posted 16 Sep 2011 Link to this post

    Here is my code, but it could not work.
    I want to show the detail row only for "Leaf" node, but not "Node" node. However, it hide everything.

    <Window x:Class="TeleTree.MainWindow"
            Title="MainWindow" Height="350" Width="525">
            <telerik:RadTreeListView x:Name="radTreeListView" AutoGenerateColumns="False" IsReadOnly="True">
                    <telerik:TreeListViewTableDefinition ItemsSource="{Binding Children}" />
                    <telerik:GridViewDataColumn  DataMemberBinding="{Binding Name}" Header="Name" Width="100"/>
                        <Grid x:Name="DetailGrid">
                            <StackPanel Orientation="Horizontal" Margin="0" Visibility="Collapsed">
                                <TextBlock Text="Type:"/>
                                <TextBox Text="{Binding Type}"/>
                            <DataTrigger Binding="{Binding Type}" Value="Leaf">
                                <Setter TargetName="DetailGrid" Property="Visibility" Value="Visible" />

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    namespace TeleTree
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
            public MainWindow()
                this.radTreeListView.ItemsSource = DataService.GetData();

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Collections.ObjectModel;
    namespace TeleTree
        public class Node
            public List<Node> Children = new List<Node>();
            public string Name;
            public string Type;
        public class DataService
            public static ObservableCollection<Node> GetData()
                ObservableCollection<Node> list = new ObservableCollection<Node>();
                Node node1 = new Node()
                    Name = "Node1",
                    Type = "Node"                
                Node node1_1 = new Node()
                    Name = "Node1_1",
                    Type = "Leaf"
                Node node2 = new Node()
                    Name = "Node2",
                    Type = "Node"
                Node node2_2 = new Node()
                    Name = "Node2_2",
                    Type = "Leaf"
                return list;

  2. Maya
    Maya avatar
    4062 posts

    Posted 19 Sep 2011 Link to this post

    Hi Ke,

    Generally, it is not quite appropriate to play along with the visibility of the RowDetails in such a manner as no matter if you set the Visibility property of the StackPanel to "Collapsed", you will still get row details and the border inside will be visualized. What you may try is to work directly with the visibility of the row details, not the element inside. 
    Do let me know in case you need any further assistance.

    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top