Welcome Guest! To enable all features please Login or Register.



How to bind a Silverlight control to a Xomega Data Property
#1 Posted : Monday, September 24, 2012 6:45:35 PM(UTC)

You can specify a binding for a Silverlight control to a data property of a Xomega data object directly in the XAML. The data object serves as a view model for your form. When the object is set as the DataContext for the view, the control will be automatically bound to the corresponding data property, which will allow Xomega Framework to keep the content of the control (such as the value or a list of values) as well as the control's state (e.g. visibility, editability, etc.) in sync with that of the data property.

In order to specify a property binding on a control, you can perform the following steps.
  1. Declare a namespace xom on your page in the XAML that maps to the Xomega Framework namespace, e.g. xmlns:xom="clr-namespace:Xomega.Framework;assembly=Xomega.Framework"
  2. Add an attribute xom:Property.Name to the XML element of the control and set its value to the name of the corresponding data property in the data object. You cannot bind the attribute value to a static string constant since the x:Static construct is not supported in Silverlight.
  3. If you want to bind to a data property that is defined on a child object of the current context object, then you can set the xom:Property.ChildObject attribute to indicate a child object's name or a dot-delimited path to it.
  4. Optionally set the xom:Property.Label attribute to indicate the label element associated with this control. This will allow Xomega Framework to show or hide the label along with the control and possibly highlight the label for required properties.
  5. Make sure that in your code behind you set the DataContext of the encapsulating panel to your data object, e.g. pnlMain.DataContext = obj;

The following XAML snippet demonstrates these steps. A TextBlock element is used as a label for the field, as the Label WPF element is not supported in Silverlight. Also, the font weight is bound to the Required attribute of the data property to highlight the labels for required fields in bold. This is due to a Silverlight limitation for style triggers that prevents from doing it in a style instead.
<TextBlock Grid.Row="5" Grid.Column="2" Name="lblFirstName" Text="First Name:"
  FontWeight="{Binding Path=(xom:Property.Required), RelativeSource={RelativeSource Self},
                       Converter={StaticResource Required2FontWeight}}"/>
<TextBox Grid.Row="5" Grid.Column="3" Name="ctlFirstName"
         xom:Property.Label="{Binding ElementName=lblFirstName}"/>
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Copyright © 2009-2022 Xomega.Net. All rights reserved.