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

How to show/hide detail according to binding object

1 Answer 242 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Ke
Top achievements
Rank 1
Ke asked on 16 Sep 2011, 02:54 PM
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"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        mc:Ignorable="d" 
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <telerik:RadTreeListView x:Name="radTreeListView" AutoGenerateColumns="False" IsReadOnly="True">
            
            <telerik:RadTreeListView.ChildTableDefinitions>
                <telerik:TreeListViewTableDefinition ItemsSource="{Binding Children}" />
            </telerik:RadTreeListView.ChildTableDefinitions>
            
            <telerik:RadTreeListView.Columns>
                <telerik:GridViewToggleRowDetailsColumn/>
                <telerik:GridViewDataColumn  DataMemberBinding="{Binding Name}" Header="Name" Width="100"/>
            </telerik:RadTreeListView.Columns>
            
            <telerik:RadTreeListView.RowDetailsTemplate>
                <DataTemplate>
                    <Grid x:Name="DetailGrid">
                        <StackPanel Orientation="Horizontal" Margin="0" Visibility="Collapsed">
                            <TextBlock Text="Type:"/>
                            <TextBox Text="{Binding Type}"/>
                        </StackPanel>
                    </Grid>
                    <DataTemplate.Triggers>
                        <DataTrigger Binding="{Binding Type}" Value="Leaf">
                            <Setter TargetName="DetailGrid" Property="Visibility" Value="Visible" />
                        </DataTrigger>
                    </DataTemplate.Triggers>
                </DataTemplate>
            </telerik:RadTreeListView.RowDetailsTemplate>
        </telerik:RadTreeListView>
    </Grid>
</Window>


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()
        {
            InitializeComponent();
            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"
            };
 
            node1.Children.Add(node1_1);
            node2.Children.Add(node2_2);
            list.Add(node1);
            list.Add(node2);
            return list;
        }
    }
}

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 19 Sep 2011, 12:46 PM
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.

Regards,
Maya
the Telerik team

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

Tags
TreeListView
Asked by
Ke
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or