在WPF中设置datagrid单元组合框背景

时间:2012-12-27 23:12:22

标签: wpf datagrid wpfdatagrid

我有数据网格显示客户数据。有些列有组合框。在行验证错误我想将组合框背景更改为红色。我该怎么做? 我已尝试在ROW加载事件上设置新数据模板,但它不起作用。我还试图修改现有的模板,但是我收到错误,它被密封并且无法修改。

UPDATE1: 我也尝试在这里使用setter 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

0 个答案:

没有答案