我有显示客户数据的数据网格。有些列有组合框。关于行验证错误,我想将组合框背景更改为红色。我该怎么做?我尝试在 ROW 加载事件上设置新的数据模板,但它不起作用。我也尝试修改现有模板,但我收到错误,它已密封且无法修改。
更新1:我也尝试在这里使用设置器 http://www.telerik.com/community/forums/silverlight/gridview/rowloaded-event-to-change-font-style.aspx
仍然没有结果。
Update2:我在后面的代码中设置数据模板。喜欢以下
Private Sub SetDataTemplate(e As GridViewAutoGeneratingColumnEventArgs, currentCompPropdefinition As ComponentPropertyDefinition)
Dim celltemplate = Nothing
If currentCompPropdefinition.Type = GetType(Boolean) OrElse currentCompPropdefinition.ValidValues IsNot Nothing Then
If currentCompPropdefinition.Type = GetType(Boolean) Then
celltemplate = New FrameworkElementFactory(GetType(CheckBox))
celltemplate.SetBinding(CheckBox.IsCheckedProperty, New Binding(e.Column.Header))
ElseIf currentCompPropdefinition.ValidValues IsNot Nothing AndAlso currentCompPropdefinition.ValidValues.Count <> 0 Then
celltemplate = New FrameworkElementFactory(GetType(Telerik.Windows.Controls.RadComboBox))
celltemplate.SetBinding(ItemsControl.ItemsSourceProperty, New Binding() With {.Source = currentCompPropdefinition.ValidValues})
celltemplate.SetBinding(ComboBox.SelectedValueProperty, New Binding(e.Column.Header))
celltemplate.SetValue(ComboBox.BackgroundProperty, FindResource("LightBG")) '(ComboBox.BackgroundProperty, )
End If
Dim dataTemplate As New DataTemplate() With {.VisualTree = celltemplate}
dataTemplate.Seal()
e.Column.CellTemplate = dataTemplate
End If
End Sub