2013-09-27 15 views
5

我試圖創建一個綁定成基於所選項目的屬性標籤的背景色。我使用的形式:如何獲得在LightSwitch中的IContentItemProxy的SetBinding方法的路徑?

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

如果我使用「價值」爲路徑,它採用ItemDisplayTitle的值來設置使用MyIconverter()

顏色,但我真的想使用其他屬性屏幕上顯示「健康」,但是該窗口的本地屬性。

研究已經告訴我,我use the form "Details.Entity.AnotherProperty " 2012年6月6日10:16應該 - 奧蒂斯遊俠

但是當我嘗試使用「DataSourceName.MyEntityName.MyProperty」它似乎並沒有工作。 我也試過「Details.MyEntityName.MyProperty」 和絕望「Details.Entity.MyProperty」

我很確定,我只是有一個心理打嗝,但什麼都要 詳細實體AnotherProperty是什麼?我是否錯過了一個明確的參考頁面,究竟路徑應該是什麼?

+0

你是否將此添加到屏幕代碼?你的財產是在那個屏幕上的本地? – TsSkTo

+0

我將此添加到屏幕代碼。該屬性位於數據源中,但也顯示在該屏幕上。 –

+0

我做了類似的事情,但在xaml中綁定了我的控件。如果將此代碼添加到屏幕中,則您的實體應顯示在屏幕數據上下文中。 xaml中的'this.customers.FirstName'或'this.CreatedScreenProperty'這些屬性的路徑前面是「屏幕」,比如'{Binding Path =「Screen.MyProperty Mode =」TwoWay}「 – TsSkTo

回答

2

的問題是,你應該在數據網格添加一個處理程序每一行。他們是3個簡單的步驟。

拳的結果,通知比可以綁定所有行或單個控制在排:

enter image description here

  • 步驟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 
  • 步驟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 

這是數據網格的處理程序。結合everyrow內部功能:

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 

感謝:

+0

謝謝。我想過去幾天我一直在爲一般概念而苦苦掙扎。今天我會再試一次。 –