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"
            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;
            }
        }
    }
    

  2. Maya
    Admin
    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.

    Regards,
    Maya
    the Telerik team

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

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top