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

Configure RadTreeListView line

3 Answers 138 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Fabiana
Top achievements
Rank 1
Fabiana asked on 18 May 2010, 08:39 PM
Hi support!

I would like to know how to configure a RadTreeListView line if user click in a hyperlink inside cell and this line is bold... but I would like to set to normal fornt  all line  , for example:
Thanks!


--------------------------------MainPage.xaml-----------------------


<UserControl x:Class="SilverlightApplication1.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:SilverlightApplication1"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        xmlns:nav="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"
             mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             Height="213" Width="469" xmlns:my="clr-namespace:Telerik.Windows.Controls.TreeView;assembly=Telerik.Windows.Controls.Navigation">

    <UserControl.Resources>
        
        <telerik:CellTemplate x:Key="firstNameTemplate" >
            <HyperlinkButton  Content="{Binding FirstName}" Foreground="Black" IsTabStop="False" FontWeight="Bold" VerticalAlignment="Center"  HorizontalAlignment="Left" Margin="0,3,0,3" Click="Cell_Click"/>
        </telerik:CellTemplate>

        <telerik:CellTemplate x:Key="lastNameTemplate">
            <HyperlinkButton   Content="{Binding LastName}" Foreground="Black" IsTabStop="False"  FontWeight="Bold" VerticalAlignment="Center"  HorizontalAlignment="Left" Margin="0,3,0,3" Click="Cell_Click"/>
        </telerik:CellTemplate>
        
        <DataTemplate x:Key="itemTemplate">
            <Grid />
        </DataTemplate>
    </UserControl.Resources>
    
    

    <nav:RadTreeListView Background="White" x:Name="RadTreeListViewTest" BorderBrush="#a9a9a9" BorderThickness="1" HorizontalContentAlignment="Center" Width="415" Height="170" SelectionMode="Single"
                         ItemTemplate="{StaticResource itemTemplate}"
                                                    IsSingleExpandPath="False"
                                                    IsExpandOnSingleClickEnabled="True"
                                                    IsLineEnabled="True" IsEditable="True">

        <nav:RadTreeListView.Columns>

            <nav:RadColumn Header="First Name" PropertyName="FirstName" Width="150" IsEditable="True" Foreground="Black" CellTemplate="{StaticResource firstNameTemplate}" />

            <nav:RadColumn Header="Last Name" PropertyName="LastName" Width="150" IsEditable="True" Foreground="Black" CellTemplate="{StaticResource lastNameTemplate}"/>

        </nav:RadTreeListView.Columns>


    </nav:RadTreeListView>

</UserControl>


--------------------------------MainPage.xaml.cs-----------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections;
using System.Collections.ObjectModel;


namespace SilverlightApplication1
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            //Add only Folders, after click add parents...
            IList itemsSource = new ObservableCollection<object>();
            itemsSource = new NameList();

            this.RadTreeListViewTest.ItemsSource = itemsSource;
        }


        private void Cell_Click(object sender, RoutedEventArgs e)
        {
            object m_control = sender;
            Type m_control_type = m_control.GetType();

            if (m_control_type.Name == "HyperlinkButton")
            {
                //Set to normal Font
                ((HyperlinkButton)sender).FontWeight = FontWeights.Normal;

            }
        }
    }
}


------------------NamedList.cs class-----------------------

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;


public class NameList : ObservableCollection<PersonName>
{
    public NameList()
        : base()
    {
        Add(new PersonName("XX", "11"));
        Add(new PersonName("WW", "22"));
        Add(new PersonName("AA", "33"));
        Add(new PersonName("QQ", "44"));
        Add(new PersonName("RR", "55"));
    }
}

public class PersonName
{
    private string firstName;
    private string lastName;

    public PersonName(string first, string last)
    {
        this.firstName = first;
        this.lastName = last;
    }

    public string FirstName
    {
        get { return firstName; }
        set { firstName = value; }
    }

    public string LastName
    {
        get { return lastName; }
        set { lastName = value; }
    }
}


3 Answers, 1 is accepted

Sort by
0
Fabiana
Top achievements
Rank 1
answered on 19 May 2010, 01:59 PM
Another question based in this example :

I would like to set Font Bold just for some items in TreeLIstView ... and in a Constructor, not in MainPage.xaml code, example:
How to do it??
Thanks!


  public MainPage()
        {
            InitializeComponent();

          
            IList itemsSource = new ObservableCollection<object>();
            itemsSource = new NameList();
            this.RadTreeListViewTest.ItemsSource = itemsSource;

            for (int i = 0; i < RadTreeListViewTest.Items.Count; i++)
            {
                PersonName sItem = (PersonName)RadTreeListViewTest.Items[i];
                if ((sItem.FirstName == "XX") || (sItem.FirstName == "RR"))
                {
                    //Set bold node item HERE!! HOW TO DI IT???
                    //????

                    //????
                }

            }
        

        }


0
Accepted
Miroslav
Telerik team
answered on 25 May 2010, 08:01 AM
Hi Fabiana,

Working with the TreeListViewItem's / Cells from code is possible but is more difficult because cells can be recreated or recycled and it is difficult to manage the changes.

It is best to work with your data and databind the FontWeight property. If this property is observable, you will be able to change it easily at runtime as well. I modified one of the previous projects I sent you, it is attached.

The border that appears when you click the hyperlink button is the focus visual of the TreeListViewItem. It appears because the control that you click (the HyperlinkButton) cannot be focused. This is determined by the IsTabStop property. You can of course disable the focus of TreeListViewItems as well but this will mean that there will be no keyboard navigation within the control.

A better approach here may be to make the hyperlink focusable (IsTabStop=true) but edit its template to remove its border.

Likewise, the template of the TreeListViewItem can be edited to remove its border as well.

Best wishes,
Miroslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Fabiana
Top achievements
Rank 1
answered on 25 May 2010, 05:21 PM
Miroslav, thank you very much!
Tags
TreeListView
Asked by
Fabiana
Top achievements
Rank 1
Answers by
Fabiana
Top achievements
Rank 1
Miroslav
Telerik team
Share this question
or