问题是您应该为数据网格上的每一行添加一个处理程序。它们是 3 个简单的步骤。
拳头结果,请注意,您可以绑定所有行或行中的单个控件:
这是我的转换器:
Public Class BooleanDateConverter
Implements System.Windows.Data.IValueConverter
Public Function Convert(ByVal value As Object,
ByVal targetType As System.Type,
ByVal parameter As Object,
ByVal culture As System.Globalization.CultureInfo) _
As Object Implements System.Windows.Data.IValueConverter.Convert
If DirectCast(value, Boolean) Then
Return New System.Windows.Media.SolidColorBrush(
System.Windows.Media.Color.FromArgb(170, 102, 255, 245))
Else
Return New System.Windows.Media.SolidColorBrush(
System.Windows.Media.Color.FromArgb(170, 255, 0, 0))
End If
End Function
Public Function ConvertBack(ByVal value As Object,
ByVal targetType As System.Type,
ByVal parameter As Object,
ByVal culture As System.Globalization.CultureInfo) _
As Object Implements System.Windows.Data.IValueConverter.ConvertBack
Return Nothing
End Function
End Class
- 第 2 步和第 3 步。绑定 datagrid 和 datagrid 行:
在 InitializeDataWorkspace 上绑定数据网格:
Private Sub Conversio_CategoriaPDI_a_ElementDeCosts_InitializeDataWorkspace(
saveChangesTo As System.Collections.Generic.List(
Of Microsoft.LightSwitch.IDataService))
AddHandler Me.FindControl(
"TConversio_CategoriaPDI_a_ElementDeCosts"
).ControlAvailable, AddressOf bindejarDataGrid
End Sub
这是数据网格的处理程序。绑定到函数内部的每一行:
Private Sub bindejarDataGrid(
sender As Object,
e As Microsoft.LightSwitch.Presentation.ControlAvailableEventArgs)
AddHandler DirectCast(e.Control, Windows.Controls.DataGrid
).LoadingRow, AddressOf bindejar
End Sub
为每一行绑定一些控制行:
Private Sub bindejar(sender As Object,
e As Windows.Controls.DataGridRowEventArgs)
Dim b As Windows.Data.Binding = New Windows.Data.Binding("parametritzat")
b.Mode = Windows.Data.BindingMode.OneTime
b.Converter = New BooleanDateConverter
b.ValidatesOnExceptions = True
e.Row.SetBinding(System.Windows.Controls.Label.BackgroundProperty, b)
End Sub
谢谢: