locked
Difference between SetProperty or ControlAvailable event... RRS feed

  • Question

  • Hey experts,

    I'm saying two ways to do (imho) the same: setting a property on a particular control.  The first would be (example from http://social.msdn.microsoft.com/Forums/en-US/lightswitch/thread/e0ea84b6-f0f4-4d13-a279-7f91a655fa3f) subscribing to the ControlAvailable event then setting properties on the control in the event handler:

    AddHandler Me.FindControl("dtpDate").ControlAvailable, AddressOf DtpDate_ControlAvailable
    
    Private Sub DtpDate_ControlAvailable(sender As Object, e As ControlAvailableEventArgs)
      Dim dtpDate As DatePicker = TryCast(e.Control, DatePicker)
      dtpDate.DisplayDateStart = DateTime.Now
      dtpDate.DisplayDateEnd = DateTime.Now.AddYears(10)
    End Sub

    The second would be to use the SetPropertyMethod directly on the IContentItemProxy (or what's the interface called :-s):

    Me.FindControl("dtpData").SetProperty("DisplayDateStart", DateTime.Now)
    Me.FindControl("dtpData").SetProperty("DisplayDateEnd", DateTime.Now.Addyears(10))

    I was wondering...

    * Are both methods doing the same? Is there a limitation in one that doesn't exist in the other?

    * Is there a general consensus on or a reason why one method might be preferred over the other?

    Keep rocking LS!

    Jan


    It's your story - time to switch on the innovation. || About me || LightSwitch blog

    Monday, May 21, 2012 5:38 PM

Answers

  • The two methods that you are describing are completely different.

    The first one is for directly setting property values on Silverlight controls.

    The second is setting property values on the usage of LightSwitch control (a Silverlight control with LightSwitch metadata). When using the SetProperty method on an IContentItemProxy instance, think of it as programmatically setting the properties that are found in the property sheet when selecting a LightSwitch control in the screen designer.


    Justin Anderson, LightSwitch Development Team

    Monday, May 21, 2012 10:46 PM
    Moderator
  • Well, I'm no expert, so I may be completely wrong here, but it seems to me that the set of properties accessible via SetProperty is pretty tiny.  Aren't those just the properties surfaced in the designer?

    As an example, you can do this via the ControlAvailable approach:

    this.FindControl("grid").ControlAvailable += (s,e) =>
    {
      var dataGrid = e.Control as DataGrid;
      dataGrid.AlternatingRowBackground = new SolidColorBrush(Colors.Orange);
    };

    But

    this.FindControl("grid").SetProperty("AlternatingRowBackground",new SolidColorBrush(Colors.Orange))

    produces an error.


    My Blog: dotnetlore.com Twitter: @DotNetLore

    Monday, May 21, 2012 9:54 PM

All replies

  • Well, I'm no expert, so I may be completely wrong here, but it seems to me that the set of properties accessible via SetProperty is pretty tiny.  Aren't those just the properties surfaced in the designer?

    As an example, you can do this via the ControlAvailable approach:

    this.FindControl("grid").ControlAvailable += (s,e) =>
    {
      var dataGrid = e.Control as DataGrid;
      dataGrid.AlternatingRowBackground = new SolidColorBrush(Colors.Orange);
    };

    But

    this.FindControl("grid").SetProperty("AlternatingRowBackground",new SolidColorBrush(Colors.Orange))

    produces an error.


    My Blog: dotnetlore.com Twitter: @DotNetLore

    Monday, May 21, 2012 9:54 PM
  • Jewel, you're my light in the darkness... :-)

    It's your story - time to switch on the innovation. || About me || LightSwitch blog

    Monday, May 21, 2012 10:18 PM
  • The two methods that you are describing are completely different.

    The first one is for directly setting property values on Silverlight controls.

    The second is setting property values on the usage of LightSwitch control (a Silverlight control with LightSwitch metadata). When using the SetProperty method on an IContentItemProxy instance, think of it as programmatically setting the properties that are found in the property sheet when selecting a LightSwitch control in the screen designer.


    Justin Anderson, LightSwitch Development Team

    Monday, May 21, 2012 10:46 PM
    Moderator