Data binding 如何在运行时在silverlight中绑定列的背景?

Data binding 如何在运行时在silverlight中绑定列的背景?,data-binding,silverlight-4.0,Data Binding,Silverlight 4.0,我有一个网格,里面有很多列。首先,这个网格是在运行时在代码隐藏中构建的,在XAML中除了通用网格之外没有多少代码,所以我不能在设计时绑定列背景。我一直在阅读各种博客和问题,发现以下是最接近的答案 SolidColorBrush backgroundBrush = new SolidColorBrush(); Binding b = new Binding("BackGroundColor"); b.Converter = new ColorConverterForReadOnly(); //Th

我有一个网格,里面有很多列。首先,这个网格是在运行时在代码隐藏中构建的,在XAML中除了通用网格之外没有多少代码,所以我不能在设计时绑定列背景。我一直在阅读各种博客和问题,发现以下是最接近的答案

SolidColorBrush backgroundBrush = new SolidColorBrush();
Binding b = new Binding("BackGroundColor");
b.Converter = new ColorConverterForReadOnly(); //This converter return color based on parameter
b.ConverterParameter = data;
BindingOperations.SetBinding(backgroundBrush, SolidColorBrush.ColorProperty, b);
column.Background = backgroundBrush;
当我运行代码时,绑定没有发生,我在转换器的第一行中放了一个断点,以查看调试是否命中了转换器,它是否没有命中转换器。如果我愿意

column.Background = new SolidColorBrush(Colors.Blue)
我可以看到列颜色设置为蓝色

在不允许调用转换器的绑定中,我缺少了什么


谢谢,

绑定的目标是BackGroundColor属性。要命中绑定,列控件的DataContext必须是具有BackGroundColor属性的对象。

这很有意义。在本文中,我的专栏有接受solidcolorbrush的背景,您知道我可能需要将其绑定到哪个属性吗?