Silverlight Databinding

Post on 24-May-2015

855 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

About Databing in Silverlight

Transcript

DATABINDINGDATABINDINGusingusing

silverlight 2.0silverlight 2.0

SRISAKTHISRISAKTHICHIPKIDZCHIPKIDZ

AGENDAAGENDA

DataBindingDataBinding Binding ExpressionBinding Expression DataTemplateDataTemplate ConvertersConverters BindingModesBindingModes

DATABINDINGDATABINDING Databinding is a mechanism for moving the data from Databinding is a mechanism for moving the data from

objects into UI controls.objects into UI controls.

Databinding is the magic that that sits between our Databinding is the magic that that sits between our objects (know as a objects (know as a modelmodel) and the UI (known as a ) and the UI (known as a viewview).).

BINDING EXPRESSIONBINDING EXPRESSION

For basic databindingFor basic databinding 11.Binding Expression.Binding Expression 22.Data context .Data context A binding expression is used inside the XAML to A binding expression is used inside the XAML to

describe the name of the property that we want describe the name of the property that we want fetched from the model.fetched from the model.For example,For example,

<TextBlock Text="{Binding Name}" /> <TextBlock Text="{Binding Name}" />

Contd…Contd…

Most Silverlight controls will expose a DataContext Most Silverlight controls will expose a DataContext property. property.

For exampleFor example Employee employee = new Employee() Employee employee = new Employee() {{ Name=“Sakthi”;Name=“Sakthi”; } this.DataContext = employee;} this.DataContext = employee;

DATATEMPLATEDATATEMPLATE

A A data templatedata template describes the controls we want to use describes the controls we want to use when displaying each individual item in a collection.when displaying each individual item in a collection.

For exampleFor example<ListBox ItemsSource="{Binding}"> <ListBox ItemsSource="{Binding}"> <ListBox.ItemTemplate> <ListBox.ItemTemplate> <DataTemplate> <DataTemplate> <TextBlock Text="{Binding Name}"></TextBlock> <TextBlock Text="{Binding Name}"></TextBlock> </DataTemplate></DataTemplate></ListBox.ItemTemplate> </ListBox.ItemTemplate>

CONVERTERCONVERTER

Silverlight allows you to dynamically convert values Silverlight allows you to dynamically convert values during data binding.during data binding.

You can accomplish this by first creating a custom class You can accomplish this by first creating a custom class that represents a value converter. that represents a value converter.

This value converter can then be referenced in an This value converter can then be referenced in an XAML file. XAML file.

BINDING MODESBINDING MODES Three BindingModes are availableThree BindingModes are available

1.1.One-way BindingOne-way Binding

2.2.Two-way BindingTwo-way Binding

3.3.OneTime BindingOneTime Binding

The One-way BindingMode is the default option used when you create a Binding.

Contd…Contd…

This option gives you the ability to automatically receive changes from a source property.

Contd…Contd…

Two-way binding enables two properties that are bound to change each other.

The OneTime option sets the target property to the source property when a binding is initially made.

CONCLUSIONCONCLUSION Silverlight data binding features are flexible and Silverlight data binding features are flexible and

powerful, and provide you with everything you need to powerful, and provide you with everything you need to build an effective business application.build an effective business application.

It provide properties such as It provide properties such as 1.CanUserResizeColumns1.CanUserResizeColumns 2.GridlinesVisibility2.GridlinesVisibility 3.HeaderVisibility3.HeaderVisibility 4.RowDetailsVisibility and RowDetailsTemplate4.RowDetailsVisibility and RowDetailsTemplate 5.SelectionMode5.SelectionMode 6.Opacity6.Opacity

www.shakthee-silverlight.blogspot.comwww.shakthee-silverlight.blogspot.com

www.shakthee.webs.comwww.shakthee.webs.com

THANK YOUTHANK YOU

top related