2011-01-20 46 views
0

我有一堆列中的网格。开始使用这个网格是在运行时在代码背后建立的,在XAML中除了泛型网格外没有太多的代码,所以我不能在设计时绑定列背景。我一直在阅读各种博客和问题,并发现以下是最接近的答案。如何在运行时绑定silverlight中的列的背景?

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) 

我可以看到列颜色设置为蓝色。

我在没有让转换器调用的绑定中丢失了什么?

谢谢,

回答

0

绑定的目标是“BackGroundColor”属性。为了绑定被击中,列控件的DataContext需要是一个具有“BackGroundColor”属性的对象。

+0

它是有道理的。在这种情况下,我的专栏有背景,接受solidcolorbrush,任何想法,我可能需要绑定它的属性? – Nair 2011-01-20 16:00:00

相关问题