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

Change Checked Items to Bold

4 Answers 71 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
George
Top achievements
Rank 1
George asked on 17 Oct 2011, 12:40 AM

How can i change the checked items and it’s ancestors to bold font?

Thanks in advance.

 

4 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 19 Oct 2011, 01:35 PM
Hi George,

 I prepared a sample for you that meets your requirement in DataBinding scenario. I bind the FontWeight property of the TextBlock from the ItemTemplate to a CheckedState property of the ViewModel. The CheckState of the RadTreeViewItems is bound to the CheckedState via ContainerBindings. Please note that you need the child items expanded before checking their parent. Do not hesitate to ask if you need further assistance.

Regards,
Petar Mladenov
the Telerik team

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

0
George
Top achievements
Rank 1
answered on 19 Oct 2011, 06:37 PM
Hi Petar,

Thanks for your response, I think some files are missing from the zip. Could not find the "TreeView.csproj" file. Can you please zip again and send to me?

Thanks

Edit:
Please ignore this. I am able to see the files.
0
George
Top achievements
Rank 1
answered on 19 Oct 2011, 08:40 PM

Hi Petar,

That was excellent. Thanks for the code snippet.

I have few more conditions to add this scenario.

  1. According to the business requirement I have IsTriStateMode = “false”
  2. Like I asked initially I would like to have the ancestors of the checked item also shown as bold.  
  3. I would like to do this change (bold/normal)in view (either in .xaml or .cs file)
  4. I have ViewModel defined in the following way, which makes changes to the property of an object does not reflect back to UI. In other words unless I refresh the entire Hierarchy object the changes inside this object does not take effect to UI.

 

Model

 

   public class Hierarchy

    {

        public string Name { get; set; }

        public Guid Id { get; set; }

        public Guid ParentId { get; set; }

        public ObservableCollection<Hierarchy> ChildCollection { get; internal set; }

        public ToggleState ToggleState { get; set; }

    }

 

ViewModel

 

    public class HierarchyViewModel : ViewModelBase

{

        public ObservableCollection<Hierarchy> Hierarchy

        {

            get

            {

                return this.hierarchy;

            }

 

            private set

            {

                if (this.hierarchy != value)

                {

                    this.hierarchy = value;

                    RaisePropertyChanged("Hierarchy");

                }

            }

        }

}

 Looking forward for your solution on this scenario,

Thanks

0
Petar Mladenov
Telerik team
answered on 24 Oct 2011, 03:38 PM
Hi George,

 I modified  the last solution I gave you in the following way:
  1.Set the IsInTriStateMode to false;
  2. The Hierarchy class now inherits the ViewModelBase and when the ToggleState is changed the UI is notified.
  3. When the ToggleState is set to On, all the children nodes' ToggleStates are also set to On. This way we implement a kind of partial TriState behavior. It should be easily corrected if needed (with code only in the ViewModels).

private ToggleState toggleState;
 
       public ToggleState ToggleState
       {
           get { return toggleState; }
           set
           {
               toggleState = value;
               if (value == ToggleState.On)
               {
                   foreach (var item in ChildCollection)
                   {
                       item.ToggleState = ToggleState.On;
                   }
               }
               this.OnPropertyChanged("ToggleState");
           }
       }


Please let us know if this satisfies you.

Kind regards,
Petar Mladenov
the Telerik team

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

Tags
TreeView
Asked by
George
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
George
Top achievements
Rank 1
Share this question
or