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 7624337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:56:10+00:00 2026-05-31T04:56:10+00:00

I want to implement that when a textbox value is changed, my Add button

  • 0

I want to implement that when a textbox value is changed, my Add button become available.

I bind the textbox with viewModel:

<TextBox Name="nameTbx" Text="{Binding Path=NewNode.Name, Mode=TwoWay}" />

My button:

<Button Content="Add" Command="{Binding Path=AddNewNodeProperty}"/>

In the XAML code behind i set the DataContext to my ViewModel. ViewModel looks like:

/* code*/

private Node _newNode = new Node();
public Node NewNode
{
    get
    {
        return _newNode;
    }
    set
    {
        _newNode = value;
        OnPropertyChanged("NewNode");
    }
}

private AddNode _addNewNodeProperty;
    public AddNode AddNewNodeProperty
    {
        get
        {
            return _addNewNodeProperty;
        }
    }

In a constructor i initialize the _addNewNodeProperty

this._addNewNodeProperty = new AddNode(this);

Here is my AddNode class:

public class AddNode : ICommand
{
    private ServiceMapViewModel viewModel;

    public AddNode(ServiceMapViewModel viewModel)
    {
        this.viewModel = viewModel;
        this.viewModel.PropertyChanged += (s, e) =>
        {
            if (CanExecuteChanged != null)
            {
                CanExecuteChanged(this, new EventArgs());
            }
        };
    }

    public bool CanExecute(object parameter)
    {
        bool b = !string.IsNullOrWhiteSpace(this.viewModel.NewNode.Name);

        return b;
    }

    public event EventHandler CanExecuteChanged;

    public void Execute(object parameter)
    {
        this.viewModel.AddNewNode();
    }
}

And finally my Node class:

public class Node
{
    public string Name { get; set; }

    public bool? IsChecked { get; set; }

    public Group Group { get; set; }

    public Category Category { get; set; }

    public string Metadata { get; set; }

    public List<string> Children = new List<string>();

    public List<string> Parents = new List<string>();
}

The problem is that when i change my textbox text, NewNode is getting the value for me, but it supposed to set .

Tnx in advanced!

EDIT
Let me add something:

I also have a datagrid on the screen and when Selected Item is changed, my Add butom become available.

Selected Item:

<DataGrid Name="nodeDataGrid" ItemsSource="{Binding Path=MyServiceMap.Nodes}"
        Background="Silver" Margin="0,34,10,10" IsReadOnly="True" SelectedItem="{Binding Path=SelectedNode}"  >

And VM:

private Node _selectedNode = new Node();
    public Node SelectedNode
    {
        get
        {
            return _selectedNode;
        }
        set
        {
            _selectedNode = value;
            OnPropertyChanged("SelectedNode");
        }
    }
  • 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-31T04:56:12+00:00Added an answer on May 31, 2026 at 4:56 am

    Your TextBox is bound to the Name property of your Node object. The Name property does not raise a PropertyChanged event when it changes. Only the entire NewNode property will raise the event when it is changed.

    Edit to offer a suggestion

    One approach would be to create a NodeViewModel class which, as mtaboy suggested, would implement the INotifyPropertyChanged interface. You would create whatever properties on the ViewModel that you would want to expose to your user. You can think of the ViewModel as sitting between your Model (i.e., Node class) and your View (the UI shown to the user).

    One change I would recommend would be to encapsulate the ICommand logic into its own class. The one I often use is the RelayCommand class which can be found in Josh Smith’s MVVM article on MSDN. If you use that class, you can define either a property or a private method in your ViewModel class which would return whether the user could Add or not. For example,

    private bool CanAddNewNode()
    {
      return !String.IsNullOrWhitespace(Name);
    }
    

    When instantiating your RelayCommand, you can pass a lambda for the second parameter that refers to that method above.

    var saveCommand = new RelayCommand(param => SaveMethod(), param => CanAddNewNode());
    

    You would expose an ICommand property from your ViewModel which would return the RelayCommand object.

    Hopefully, that gets you started.

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

Sidebar

Related Questions

Microsoft has announce that WindowsLiveID become a OpenID provider . I want implement it
I want to bind a textbox to a data source so that I can
I'm using R5RS Scheme and I just want to implement a function that returns
We want to implement chat on our website so that users can communicate with
When I implement objects that I want to compare using the IEquatable<T> interface :
I want to implement a derived class that should also implement an interface, that
I want to implement a view in an iPhone application that is essentially like
I have this algorithm that I want to implement on VB6. Sub Main() dim
I want to implement a basic search/replace translation table in C; that is, it
I want to implement a version of Benford's law ( http://en.wikipedia.org/wiki/Benford%27s_law ) that basically

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.