谁能告诉我什么是以下XAML片段的c#等价物?
<my:DataGridTextColumn Visibility="{Binding Path=DataColumns[21].IsVisible,Source={StaticResource viewmodel},Converter={StaticResource vc}}" Binding="{Binding SdDevDuration}" />
它的可见性绑定我无法正确. DataGridTextColumn不是FrameworkElement,因此没有SetBinding方法.
提前致谢,
马特
解决方法
我解决了这个问题.对于任何感兴趣的人,您可以使用BindingOperation.SetBinding方法.
完整的代码是,
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);