Data binding in silverlight

1,028 views
980 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,028
On SlideShare
0
From Embeds
0
Number of Embeds
382
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Data binding in silverlight

  1. 1. Data Binding in Silverlight<br />Mahender<br />Senior Software Engineer<br />United Health Group<br />
  2. 2. Mahender Sarangam<br />Having close to 5 years of experience. Working as a Senior Software Engineer in United Health Group. Good Knowledge on C#, ASP.NET, Silverlight, WPF ,SQL Server, Team Foundation Server(TFS) and SharePoint Technology. MCTS Certified in Web Technologies.<br />
  3. 3. Data Binding <br />Data binding is a mechanism for moving the data from objects into UI controls.<br />Data binding is a key in Silverlight that allows data shown on UI and then process changes.<br /> Data binding is a process that tells Silverlight to extract a property value from a source object and use it to set a property in a target object. Here Target Object which inherit from Dependency Object and its property must be a Dependency property.<br />Data Binding works with Public properties of Source object. It does not work for fields.<br />
  4. 4. Data Binding<br />We use Binding expression for binding Source property to Target property. Here we don’t mention source object which contain data. Generally in WPF/Silverlight, control uses Data context as Source Object or try to use source property of Binding expression.<br /><UserControl.Resources><br /><local:Product x:Key="resourceProduct"<br />ModelNumber="AEFS100"<br />ModelName="Portable Defibrillator" UnitCost="77"<br />Description="Analyzes the electrical activity of a person's heart and applies<br />an electric shock if necessary."><br /></local:Product><br /></UserControl.Resources><br /><TextBox<br />Text="{Binding ModelNumber, Source={StaticResourceresourceProduct} }“></TextBox><br />
  5. 5. INotify Property Changed<br />The INotifyPropertyChanged interface is a key part of the data binding infrastructure available in Silverlight. It contains a single event named PropertyChanged that is used to notify objects when a particular property value changes.<br />
  6. 6. Data Context<br />Data Context: The Data Context refers to a source of data that can be bound to a target. The Data Context often is set to an instance of an entity<br />Data Context is inherited to child elements and this makes it ideal for scenarios where you want to bind multiple elements to a single data source.<br />Data Context is a property of Framework Element<br />We use Binding expression for binding Source property to Target property<br />
  7. 7. Target Null Value and Fall Back values<br />Target Null values are default values i.e. when bound data is NULL or there may be cases where value bounded is NULL. <br />For example: <br /> <TextBox Text="{Binding ModelName, TargetNullValue='[No Model Name Set]' }"></TextBox><br />There might be cases , When Binding Properties to Target control ,binding throws exception or any binding operation failure , Fall back value provide a fall back value when binding is unable to return value<br /><TextBox Text="{Binding ModelName, FallBackvalue='[No Model Name Set]' }"></TextBox>.<br />String Format : Allows formatting of the bound value using standard formatting expressions. <br /><TextBlock x:Name="CurrencyExample" Text="{Binding Cost, StringFormat=C}"></TextBlock> <br /><TextBlock x:Name="BirthDateValueTextBlock" Text="{Binding BirthDate, StringFormat=MM/dd/yyyy}"></TextBlock><br />
  8. 8. Data Flow <br />Each Binding expression has Mode property which determines how and when the data flows. <br />There are 3 types of Data binding<br />One Time Binding : Target property is set initially with the source data when the binding is created<br />One way Binding : Update targets whenever source data changes. This is default<br />Two Way Binding : The target property is updated when the source property changes, and the source Property is updated when the target property changes.<br />UpdateSourceTrigger : Silverlight supports only two values for Update SourceTrigger: Default and Explicit. It isn’t possible to choose PropertyChanged<br />ValidateonErrors and validate on exceptions<br />
  9. 9. Thank you!<br />

×