Nathan
Nathan

Reputation: 5233

WPF Binding with a Border

I have a group of borders that make up a small map. Ideally I'd like to be able to bind the border's background property to a property in a custom list and when that property changes it changes the background.

The tricky thing is, I have to do this in code behind.

Upvotes: 0

Views: 597

Answers (1)

itowlson
itowlson

Reputation: 74802

Use the FrameworkElement.SetBinding method:

myBorder.SetBinding(Border.BackgroundProperty, "CurrentBackground");

or, if you need sources and converters and things:

myBorder.SetBinding(Border.BackgroundProperty,
  new Binding(somePath) {
    Source = something,
    Converter = new WonderConverter()
    // etc.
  });

Upvotes: 2

Related Questions