Ruben
Ruben

Reputation: 55

Binding view with model (view doesn't update)

i'm implementing something, that if i select something in my listbox, some textboxes come visible. So i can fill in some details of the selected item. I already implemented a visibilityconverter and this is my code of xaml and viewmodel:

The items in the listbox are objects of class Question

public Question SelectedQuestionDropList
        {
            get { return selectedQuestionDrop; }
            set
            {
            selectedQuestionDrop = value;
            OnPropertyChanged("SelectedQuestionDropList");

            Visible = true;

            }
        }

this is my property of Visibility:

public Boolean Visible
        {
            get { return visible; }
            set { visible = value; }
        }

my xaml looks like this:

<ListBox SelectedItem="{Binding Path=SelectedQuestionDropList, UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" 
 DisplayMemberPath="Description"
  />

 <TextBox Height="23" Visibility="{Binding Path=Visible, Converter={StaticResource boolToVis},UpdateSourceTrigger=PropertyChanged,Mode}"  />

But i have a problem, when i select something, the property visible is set to true, but the visibility of the textbox stays false .. so my view doesn't update with the viewmodel. someone who knows what i am doing wrong?

Upvotes: 2

Views: 660

Answers (1)

thumbmunkeys
thumbmunkeys

Reputation: 20764

In order for the Visibility Binding to update you have to change your property to call OnPropertyChanged:

    public Boolean Visible
    {
        get { return visible; }
        set 
        { 
           visible = value; 
           OnPropertyChanged("Visible");
        }
    }

Upvotes: 1

Related Questions