silverlight databinding

13
DATABINDING DATABINDING using using silverlight 2.0 silverlight 2.0 SRISAKTHI SRISAKTHI CHIPKIDZ CHIPKIDZ

Upload: srisakthi-kannan

Post on 24-May-2015

860 views

Category:

Technology


2 download

DESCRIPTION

About Databing in Silverlight

TRANSCRIPT

Page 1: Silverlight Databinding

DATABINDINGDATABINDINGusingusing

silverlight 2.0silverlight 2.0

SRISAKTHISRISAKTHICHIPKIDZCHIPKIDZ

Page 2: Silverlight Databinding

AGENDAAGENDA

DataBindingDataBinding Binding ExpressionBinding Expression DataTemplateDataTemplate ConvertersConverters BindingModesBindingModes

Page 3: Silverlight Databinding

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).).

Page 4: Silverlight Databinding

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}" />

Page 5: Silverlight Databinding

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;

Page 6: Silverlight Databinding

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>

Page 7: Silverlight Databinding

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.

Page 8: Silverlight Databinding

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.

Page 9: Silverlight Databinding

Contd…Contd…

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

Page 10: Silverlight Databinding

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.

Page 11: Silverlight Databinding

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

Page 12: Silverlight Databinding

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

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

Page 13: Silverlight Databinding

THANK YOUTHANK YOU