views:

935

answers:

2

Can anyone tell me what is the c# equivalent of the following snippet of XAML ??

<my:DataGridTextColumn 
                Visibility="{Binding Path=DataColumns[21].IsVisible, Source={StaticResource viewmodel}, Converter={StaticResource vc}}"                    
                Binding="{Binding SdDevDuration}"
                />

Its the visibility binding I cannot get right. DataGridTextColumn is not a FrameworkElement so no SetBinding method.

Thanks in advance,

Matt

+1  A: 

I worked this out. For anyone who's interested you can use the BindingOperation.SetBinding method.

The full code is,

var newCol = new DataGridTextColumn();
newCol.Binding = new Binding("SdDevDuration");

var visiblityBinding = new Binding("IsVisible");
visiblityBinding.Source = col;
visiblityBinding.Converter = new VisibilityConverter();                        
BindingOperations.SetBinding(newCol, DataGridTextColumn.VisibilityProperty, visiblityBinding);
Matt Randle
Accept your answer.
Sauron
I will. SO telling me I have to wait before accepting my own answer.
Matt Randle
A: 

Hi Matt,

I set the Visibility's Source to a StaticResource, but still got AG_E_BAD_PARSER runtime error, looks like it works in WPF but not in Silverlight. I'm using Silverlight 3 DataGridTextColumn. have you tried this in Silverlight?

I found another link related to this issue, but I haven't found the solution yet. http://stackoverflow.com/questions/983272/silverlight-datagridtextcolumn-binding-visibility

Thanks, Sissy

Sissy Zhang