views:

620

answers:

1

I have a custom object Foo with a boolean property called Flagged and when someone successfully types something in a text box it changes flagged to true and updates another textblock on the screen with some text. The problem is I can get it to work on loading the initial data but nothing happens when the user successfully types something in to flip the flag.

I have to do the majority of this in code behind and I have implemented INotifyPropertyChanged on my object Foo. What is wrong with my code below?

Thanks.

private Border CreateNewBorder()
    {
        Border b = new Border();
        TextBlock tb = new TextBlock();
        tb.TextAlignment = TextAlignment.Center;

        b.Style = (Style)this.FindResource("myBorder");
        tb.SetBinding(TextBlock.TextProperty, CreateBinding());
        b.Child = tb;

        return b;
    }

    private Binding CreateBinding()
    {
        Binding bind = new Binding();
        bind.Source = Foo;
        bind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
        bind.Mode = BindingMode.TwoWay;
        bind.Path = new PropertyPath("Flagged");
        bind.Converter = new BoolToStringConverter();

        return bind;
    }
+1  A: 

It sounds like you're probably just missing change notifications on Foo. Have you implemented INotifyPropertyChanged on Foo and called the PropertyChanged event from the Flagged setter?

John Bowen