We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Enable/Disable items in SfTreeNavigator

Thread ID:

Created:

Updated:

Platform:

Replies:

153051 Apr 6,2020 12:42 AM UTC Apr 21,2020 12:19 PM UTC WPF 8
loading
Tags: SfTreeNavigator
Mariusz Juszkiewicz
Asked On April 6, 2020 12:42 AM UTC

Does anyone know how to enable/disable menu items in SfTreeNavigator

Duraimurugan Vedagiri [Syncfusion]
Replied On April 6, 2020 04:38 PM UTC

Hi Mariusz,

Thanks for using syncfusion products.

Currently, we are trying to achieve your reported requirement and will update you the further details on April 8th, 2020.

Regards,
Durai


Duraimurugan Vedagiri [Syncfusion]
Replied On April 7, 2020 03:01 PM UTC

Hi Mariusz,

Thanks for your patience.

You can achieve your requirement by using TreeMenuItem.Enabled bool property. Please refer the below code snippet and sample for your reference.

public Form1() 
{ 
    InitializeComponent(); 
    //Adds items to the TreeNavigator. 
    treeNavigator.Header.HeaderText = "This PC"; 
    TreeMenuItem treemenuitem1 = new TreeMenuItem(); 
    treeNavigator.Items.Add(treemenuitem1); 
    treemenuitem1.Text = "Desktop"; 
    TreeMenuItem treemenuitem2 = new TreeMenuItem(); 
    treeNavigator.Items.Add(treemenuitem2); 
    treemenuitem2.Text = "Document"; 
    TreeMenuItem treemenuitem3 = new TreeMenuItem(); 
    treeNavigator.Items.Add(treemenuitem3); 
    treemenuitem3.Enabled = false; 
    treemenuitem3.ItemBackColor = Color.LightGray; 
    treemenuitem3.Text = "Downloads"; 
} 


Mariusz Juszkiewicz
Replied On April 8, 2020 12:42 AM UTC

Thanks Durai.
I am having problem opening the example link. It tell me I do not have Access.
What namespace is TreeMenuItem under? Cannot find the class.

Duraimurugan Vedagiri [Syncfusion]
Replied On April 8, 2020 05:07 AM UTC

Hi Mariusz,

Sorry for the inconvenienced cause.

Please refer the sample from the following link :

https://www.syncfusion.com/downloads/support/forum/153051/ze/SampleTreeNavigator-2035544166.zip  

Query : What namespace is TreeMenuItem under?

You, can achieve by using following namespace "using Syncfusion.Windows.Forms.Tools;".

Regards,
Durai

Mariusz Juszkiewicz
Replied On April 9, 2020 12:32 AM UTC

Sorry but I am still unable to open the example.

is Syncfusion.Windows.Forms.Tools winforms or WPF?

Duraimurugan Vedagiri [Syncfusion]
Replied On April 9, 2020 05:06 AM UTC

Hi Mariusz,

We deeply regret for the inconvenience caused.

Can achieve your requirement “How to Enable/disable menu items in SfTreeNavigator
by using IsEnable bool property. Please refer the below code snippet and sample for your reference.

Code Snippet
<Grid> 
    <navigation:SfTreeNavigator Header="Enterprise Toolkit" Margin="0,0,540,0"> 
        <navigation:SfTreeNavigatorItem Header="WinRT (XAML)" > 
            <navigation:SfTreeNavigatorItem Header="Chart"/> 
            <navigation:SfTreeNavigatorItem Header="Tools"/> 
        </navigation:SfTreeNavigatorItem> 
        <navigation:SfTreeNavigatorItem Header="Metro Studio" IsEnabled="False"/> 
    </navigation:SfTreeNavigator> 
</Grid> 

Sample : https://www.syncfusion.com/downloads/support/forum/153051/ze/TreeNavigatorExample1477148263.zip 

Regards,
Durai

Mariusz Juszkiewicz
Replied On April 20, 2020 03:40 AM UTC

Thank you for your response. This work if I define the items in XAML. My items get loaded from ViewModel class
public class TreeViewModel
    {
       
        private List<TreeModel> models;
        public List<TreeModel> Models
        {
            get { return models; }
            set { models = value; }
        }
        public TreeViewModel()
        {
            Models = new List<TreeModel>();
            TreeModel Admin = new TreeModel() { Header = "Administration" };
            TreeModel Proposals = new TreeModel() { Header = "Proposals" };
            TreeModel Estimates = new TreeModel() { Header = "Estimates" };
            TreeModel Estimators = new TreeModel() { Header = "Estimators" };
            TreeModel LabRate = new TreeModel() { Header = "Labour Rate Collection" };
            TreeModel ShiftCal = new TreeModel() { Header = "Shift Calendar Collection" };
            TreeModel CrewMix = new TreeModel() { Header = "Crew mix Collection" };
            TreeModel EstCode = new TreeModel() { Header = "Estimate Coding" };
            TreeModel Lookup = new TreeModel() { Header = "Lookup Lists" };
            TreeModel Owner = new TreeModel() { Header = "Customer/Owner List" };
            TreeModel Eng = new TreeModel() { Header = "Engineer List" };
            TreeModel Comp = new TreeModel() { Header = "Company/Division List" };
            TreeModel Propstat = new TreeModel() { Header = "Proposal Status List" };
            TreeModel PropGroup = new TreeModel() { Header = "Proposal Group List" };
            TreeModel EstType = new TreeModel() { Header = "Estimate Type List" };

            Lookup.Models.Add(Owner);
            Lookup.Models.Add(Eng);
            Lookup.Models.Add(Comp);
            Lookup.Models.Add(Propstat);
            Lookup.Models.Add(PropGroup);
            Lookup.Models.Add(EstType);

            Admin.Models.Add(Estimators);
            Admin.Models.Add(LabRate);
            Admin.Models.Add(ShiftCal);
            Admin.Models.Add(CrewMix);
            Admin.Models.Add(EstCode);
            Admin.Models.Add(Lookup);
           

            Models.Add(Proposals);
            Models.Add(Estimates);
            Models.Add(Admin);
        }
        private object selecteditem;
        public object SelectedItem
        {
            get { return selecteditem; }
            set { selecteditem = value; }
        }

Duraimurugan Vedagiri [Syncfusion]
Replied On April 21, 2020 12:19 PM UTC

Hi Mariusz,

Thanks for your update.

You can achieve your requirement “How to Enable/disable menu items in SfTreeNavigator using MVVM” to customize the SfTreeNavigator.ItemContainerStyle by binding the IsEnable property for SfTreeNavigatorItem.

Please refer the below code snippet and sample for your reference.

Code Snippet
<Grid> 
    <navigation:SfTreeNavigator ItemsSource="{Binding Models}"   
                            Header="Enterprise Toolkit" 
                            Width="300" Height="400" 
                            HorizontalAlignment="Center" 
                            VerticalAlignment="Center" > 
        <navigation:SfTreeNavigator.ItemTemplate> 
            <HierarchicalDataTemplate ItemsSource="{Binding Models}"> 
                <StackPanel Orientation="Horizontal"> 
                    <TextBlock Text="{Binding Header}"   
        VerticalAlignment="Center" Margin="18 0 0 0"/> 
                </StackPanel> 
            </HierarchicalDataTemplate> 
        </navigation:SfTreeNavigator.ItemTemplate> 
        <navigation:SfTreeNavigator.ItemContainerStyle> 
            <Style TargetType="{x:Type navigation:SfTreeNavigatorItem}"> 
                <Setter Property="IsEnabled" Value="{Binding IsEnable}"/> 
                <Style.Triggers> 
                    <Trigger Property="IsEnabled" Value="False"> 
                        <Setter Property="Background" Value="LightGray"/> 
                    </Trigger> 
                </Style.Triggers> 
            </Style> 
        </navigation:SfTreeNavigator.ItemContainerStyle> 
    </navigation:SfTreeNavigator> 
</Grid> 
 



CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon