我正在尝试创建一个绑定,以根据所选项的属性更改标签的背景颜色。我正在使用表格:
this.FindControl("ItemDisplayTitle")
.SetBinding(TextBox.BackgrounProperty, **PATH**,
new MyIconverter(), BindingMode.OneWay);
如果我使用“Value”作为路径,它使用ItemDisplayTitle的值来使用MyIconverter()
设置颜色但我真的想使用屏幕上的另一个属性“Health”,但它是此窗口的本地属性。
研究表明我应该use the form "Details.Entity.AnotherProperty " 2012年6月6日上午10:16 - 奥的斯游侠
但是当我尝试使用“DataSourceName.MyEntityName.MyProperty”时,它似乎不起作用。 我也试过“Details.MyEntityName.MyProperty” 并在绝望中“Details.Entity.MyProperty”
我很确定我只是心理打嗝,但应该怎么做 详细信息,实体和 AnotherProperty 是?我是否错过了一个明确的参考页面,确切的路径应该是什么?
答案 0 :(得分:2)
问题是您应该在数据网格上为每一行添加一个处理程序。它们是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
在InitializeDataWorkspace上绑定datagrid:
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
这是datagrid的处理程序。绑定到函数内的每一行:
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
感谢: