Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 839189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:25:40+00:00 2026-05-15T05:25:40+00:00

I have an application which shows a Tree where can select nodes of the

  • 0

I have an application which shows a Tree where can select nodes of the tree and add them to a list. To keep the code clean I have moved the TreeView into it’s own UserControl(I use this tree in several places) and xaml file. To add a node to the list I have an ‘add’ button. However I want to gray-out this ‘add’ button when none of the treeviewitems are selected. What is the wisest way to do this. I can bind to the complete usercontrol and write a more complicated converter, but this seems inelegant. Are there any simple solutions?

I would have hoped something along the lines of “ElementName=xamlFile.TargetElement” would have worked…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T05:25:41+00:00Added an answer on May 15, 2026 at 5:25 am

    Commands provide automatic disabling of buttons using them when the command cannot execute. If you create a command and add handlers for it in your UserControl the external Add Button can use the command.

    <local:TreeViewControl x:Name="Tree"/>
    <Button Content="Add" Command="{x:Static local:TreeViewControl.AddCommand}" CommandTarget="{Binding ElementName=Tree}"/>
    

    Command creation and hookup:

    public partial class TreeViewControl : UserControl
    {
        public static RoutedCommand AddCommand { get; private set; }
    
        static TreeViewControl()
        {
            AddCommand = new RoutedCommand("AddCommand", typeof(TreeViewControl));
        }
    
        public TreeViewControl()
        {
            InitializeComponent();
    
            CommandBindings.Add(new CommandBinding(AddCommand, AddExecuted, AddCanExecute));
        }
    
        public void AddExecuted(object sender, ExecutedRoutedEventArgs e)
        {
        }
    
        public void AddCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = false; // your logic here
        }
    }
    

    If using MVVM you can use DelegateCommand or RelayCommand to do similar things from a ViewModel.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a xPage application which shows list of emails of the currently logged
Hi I have a page in my java/jsp based web application which shows list
I have an application which shows a list view. I am planning to make
I have a C# application which shows the current time in a transparent .NET
In my application, I have a 'logging' window, which shows all the logging, warnings,
I have a c# application which shows images in a form. I'm trying to
So I have this extremely memory-intensive Java application I'm building, which builds a tree
I have successfully made an facebook application which shows real time data from facebook
I have to make an application which shows the contact no of the SIM
I have created an application which shows the multiple overlay as the result of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.