开发者

WPF Binding with a Border

开发者 https://www.devze.com 2022-12-23 07:39 出处:网络
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

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开发者_StackOverflow thing is, I have to do this in code behind.


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.
  });
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号