Quantcast
Channel: MVVM Light Toolkit
Viewing all articles
Browse latest Browse all 1826

New Post: How to Bind String Value to TextBox?

$
0
0
ccbVT wrote:
Is your Product class a ViewModel? If so, it should derive from ViewModelBase.
Then, your Name setter should look something like:
            set
            {
                if (Name == value)
                {
                    return;
                }
                Name = value;
                RaisePropertyChanged(() => Name);
            }
If your textbox's Text property is bound to the Name property, the textbox should update when the Name property changes.
Could you give more details?
  • How have you set the DataContext for the textbox?
  • What happens when the button is clicked?
I was thinking it was the Domain class. I am trying to go through the MIX11 video and I would think that my Product class would be my Domain class like the Friend Class is in the video.

and this would be in my View Model class

public Product Product{ get; set; }


How I have it right now I don't seem to have a DataContext on the textbox(I do have it in my layOutRoot)). What I did was like in the video. I opened blend up and dragged my VieModelLocator onto the layoutroot and then I dragged the property from the product class onto a textbox I made.
<TextBox Text="{Binding Product.Name, Mode=TwoWay}" Margin="257,211,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Width="80"/>
When I click the button I made a relay command that I grabbed off in some old book I had
        public RelayCommand AddAVendorCommand
        {
            get;
            private set;
        }
            AddAVendorCommand = new RelayCommand(() => AddVendor()); // in constructor of ViewModel

Right now it just goes to the AddVendor method and I have a break point to see if what I put in the textbox show sup in the Product object.

Viewing all articles
Browse latest Browse all 1826

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>