Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the path for the SetBinding method on an IContentItemProxy in LightSwitch?

I am trying to create a binding to change the background color of a label based on a property of the selected item. I'm using the form:

this.FindControl("ItemDisplayTitle")
        .SetBinding(TextBox.BackgrounProperty, **PATH**, 
             new MyIconverter(), BindingMode.OneWay);

If I use "Value" as the path, it uses the value of ItemDisplayTitle to set the color using MyIconverter()

But I really want to use another property "Health" which is on the screen but is a Local Property for this window.

Research has show me that I should use the form "Details.Entity.AnotherProperty " June 06, 2012 10:16 AM - Otis Ranger

But when I try to use "DataSourceName.MyEntityName.MyProperty" it does not seem to work. I've also tried "Details.MyEntityName.MyProperty" and in desperation "Details.Entity.MyProperty"

I pretty sure I'm just having a mental hiccup, but what should Details, Entity and AnotherProperty be? and am I missing a obvious reference page to what exactly the path should be?

like image 443
Wayne Arthurton Avatar asked Nov 02 '22 14:11

Wayne Arthurton


1 Answers

The issue is that you should add a handler to every row on data grid. They are 3 easy steps.

Fist the result, notice than you can bind all row or a single control in row:

enter image description here

  • Step 1. Declare converter. I assume that your converter runs fine.

This is my converter:

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
  • Step 2 and 3. Bind datagrid and datagrid rows:

Binding datagrid on 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

This is the handler for datagrid. Binding to everyrow inside function:

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

        AddHandler DirectCast(e.Control, Windows.Controls.DataGrid
                   ).LoadingRow, AddressOf bindejar
    End Sub

Binding some control row for every row:

    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

Thanks to:

  • Otis Ranger
  • pragmaswitch.com
like image 119
dani herrera Avatar answered Nov 14 '22 10:11

dani herrera