如何在LightSwitch中的IContentItemProxy上获取SetBinding方法的路径?

Way*_*ton 5 c# silverlight visual-studio-lightswitch

我正在尝试创建一个绑定,以根据所选项的属性更改标签的背景颜色.我正在使用表格:

this.FindControl("ItemDisplayTitle")
        .SetBinding(TextBox.BackgrounProperty, **PATH**, 
             new MyIconverter(), BindingMode.OneWay);
Run Code Online (Sandbox Code Playgroud)

如果我使用"Value"作为路径,它使用ItemDisplayTitle的值来使用MyIconverter()设置颜色

但我真的想使用屏幕上的另一个属性"健康",但它是此窗口的本地属性.

研究告诉我,我应该使用"Details.Entity.AnotherProperty"形式 2012年6月6日上午10:16 - Otis Ranger

但是当我尝试使用"DataSourceName.MyEntityName.MyProperty"时,它似乎不起作用.我也尝试了"Details.MyEntityName.MyProperty",并在绝望中"Details.Entity.MyProperty"

我很确定我只是心理打嗝,但是 细节,实体另一个属性应该是什么?我是否错过了一个明确的参考页面,确切的路径应该是什么?

dan*_*era 2

问题是您应该向数据网格上的每一行添加一个处理程序。只需 3 个简单步骤即可。

查看结果,注意您可以绑定所有行或行中的单个控件:

在此输入图像描述

  • 步骤1。声明转换器。我假设你的转换器运行良好。

这是我的转换器:

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
Run Code Online (Sandbox Code Playgroud)
  • 步骤2和3。绑定数据网格和数据网格行:

在 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
Run Code Online (Sandbox Code Playgroud)

这是数据网格的处理程序。绑定到函数内的每一行:

    Private Sub bindejarDataGrid(
           sender As Object, 
           e As Microsoft.LightSwitch.Presentation.ControlAvailableEventArgs)

        AddHandler DirectCast(e.Control, Windows.Controls.DataGrid
                   ).LoadingRow, AddressOf bindejar
    End Sub
Run Code Online (Sandbox Code Playgroud)

为每一行绑定一些控制行:

    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
Run Code Online (Sandbox Code Playgroud)

谢谢: