Simple Data Binding in Blend 3

I know most designers like to stick with creating the graphics and leaving all the coding  to developers, but Data Binding is so simple and could come in very handy for you one day.

Text to text binding

Text to text binding is a good place to start because it’s the most basic type of binding. It allows you to type in a text field and then display that text somewhere else, event multiple locations.

The first step is to create a TextBox (call this item Input_Text) anda TextBlock (which is updated when the content of the TextBox changes).

 

Select your TextBlock and find the “Content” property in your properties panel. Click the tiny square next to it and select “Data Binding.”



A dialogue box appears with 3 tabs across the top. Select the “Element Property” tab.

Now you should see all the items on that current page. On the left panel navigate to the Input_Text item and select it.  The right panel displays the properties available for Input_Text. Scroll down and select “Text: (String).” Then click OK.



Collapse the properties panel to see the data bound text in action!

Next up: Slider control to object height

In this demo , I bound a slider control so I can easily edit the height of the graph items. First let’s look at how to bind a slider to a rectangle’s height.

Click  the Assets tab in the top left corner (if you have the standard work space setup), and find the slider control.  If you don’t use the standard work space setup, click the Assets library button at the bottom of your tool bar on the left..

 

Place a slider control on the page. The size doesn’t matter, because we will set the values of each end of the slider and Silverlight will calculate the rest.

Next create a rectangle on the screen. You will bind your slider control to this rectangle later.

Now switch to the XAML  view for the page.



Find your slider. It will probably look something like this:
<Slider Height="42" HorizontalAlignment="Right" Margin="0,0,-13,30" VerticalAlignment="Bottom" Width="135"/>

We’ll add a few elements to this, but first let’s start by naming it “control_slider.”  Either edit it at the top of the properties tab or via XAML by adding x:Name="control_slider"

Now add a Maximum and Minimum value for the slider:Maximum=”125” Minimum=”15”

Because we are applying this to a rectangle’s height, think of these values as pixels.

Next, add  the starting value.  This will dictate where the slider is positioned when the application is loaded.
Value=”50”

You can edit all of these items in the properties panel under “common properties.”

Now the XAML for your slider control should look something like this:
<Slider x:Name="control_slider" Height="21" Maximum="125" Minimum="15" Value="125" HorizontalAlignment="Left" Width="135" IsEnabled="False" Canvas.Left="203" Canvas.Top="152"/>

To bind your slider control to the rectangle:

Select your rectangle and find the height property. Click the small square next to it and select “Data Binding.”

Then Select the “Element Properties” tab and find your slider control in the left panel. On the right panel, select the “Value: (Double)” item and click OK.

Collapse the properties panel and try out your slider!

Some other tips and hints with Data Binding

Change the mode: When you bind an element to something, the element will look like this:
Text="{Binding Text, ElementName=textBox, Mode=OneWay}"

By changing the mode from OneWay to TwoWay, you can edit either the TextBox or the TextBlock , and both will display the change. 

Note: this means both items have to be able to take input, for example, 2 text boxes. 

Try binding to other items: Instead of binding to a simple rectangle, try binding to a canvas and placing multiple items inside, like I have with my isometric graph items.

 

About the Author

Alex Knight

Alex is a Silverlight MVP with a strong focus on the graphics and user interface side of things. He runs Xamling with Jordan Knight (@jakkaj) which specialises in creating awesome experiences for Silverlight and WPF. So it doesn't matter what platform, if its xaml he digs it. If you want to find more out about Alex, check out:
AGKDesign.twitter | xamling.net

#1 Bharti on 8.04.2009 at 12:55 AM

Hi Alex,

Nice Tutorial.Impressive Example.

Just Curious about that Rectangle bars.

Did you use perspective 3d for that?

#2 Alex Knight on 8.04.2009 at 9:05 AM

Hi Bharti,

No perspective for the bars, its just a canvas, with 3 rectangles, I just skewed the side and top a little to give the isometric feel to them...

#3 Bharti on 8.04.2009 at 11:11 AM

Thanks for your quick Reply.

#4 Bharti on 8.05.2009 at 3:02 PM

Hi Alex,

I have tried your tutorial.Data binding works properly.But the problem is that when i try to increase the ht of skewed rectangle,it increases in downward direction instead of upward direction in Blend 3.

Do you have any solution for this?

Thanks

Bharti

#5 Alex Knight on 8.05.2009 at 4:10 PM

If you move the center point of the rectangle to the bottom by dragging and dropping the dot in the middle of the rectangle, if that doesn't work try changing its center point in the RenderTransform options in your property menu. Let me know how you go.

Oh and also you could try putting the rectangle inside a contain like a canvas.

#6 Tom Beeby on 8.05.2009 at 5:46 PM

Hey Alex,

nice tutorial!

#7 Bharti on 8.06.2009 at 6:26 AM

Hi Alex,

Thanks for your suggestion.I have tried all the options by changing the center point of rectangle and using rectangle with canvas.But still it is not working :(.

#8 Bharti on 8.07.2009 at 12:07 AM

Hi Alex,

I think i got the solution.

I used grid panel instead of canvas and moved center point downward and it's working.

Thanks for discussion and help.

#9 Sulumits Retsambew on 8.08.2009 at 9:26 PM

Thanks Alex. I got your point.

#10 Italian Translation on 8.11.2009 at 7:31 AM

Thnaks for the turtorial.I was looking for that info nearly 2 days.Can I copy this article on my blog?If so,please mail me,and we can exchange uesful articles in the future.

Regards,

Nick

#11 asis on 8.11.2009 at 10:48 PM

Thanks for the tutorial. can you give me some idea how to create a cutom slider control and how to bind the data.

Thank you

#12 devildev on 8.12.2009 at 7:00 AM

Hi Alex!

I apply Data Binding to "3d rectangle". Then when I move the slider it changes the other way around - the top is in place, while the bottom moves. For all other objects moving up. How to solve this problem?

Sorry for my English

#13 Alex Knight on 8.12.2009 at 10:18 AM

Hi Devildev,

This is probably because the object VerticalAlignment is set to be a certain distance from the top. Under layout there are some options to change the VerticalAlignments of the object, if it is set to top it will always be that distance from the top of your application (or the canvas it sits inside). if you change this to bottom then it should always sit that distance from the bottom and will expand upwards.

If it was aligned to the center, it would expand both directions.

It's a little hard to explain with out showing you some images but I hope this helped.

#14 Alex Knight on 8.12.2009 at 10:22 AM

Hi Asis,

The binding would be the same as in this tutorial and then you can skin your slider control by right clicking it, pointing to Edit Template and clicking Edit a Copy. In here you will see all the elements of your slider. From here you should able to edit each part of the slider to look how you wish.

Editing sliders can be quite tricky because there are a lot of bits and pieces in there to play around with.

Take the HorizontalThumb for example, its a control within your Slider, you can right click that item and edit its template.

Hope this helped.

Thanks

#15 devildev on 8.14.2009 at 4:36 PM

Hi Alex,

I understand that the transition from one state to another (from save to edit or сonversely) is made by using reverse the animation?

#16 Alex Knight on 8.14.2009 at 6:08 PM

Devildev,

Nope, all the animations are created on the fly depending on where the elements are... I have 2 states, the first showing the graph at full size and the second showing the editable items and the smaller graph, all I need to do is tell my app that when I click this button go to that state and take 3 seconds to do it. So Silverlight then calculates what it needs to do within those 3 seconds for each item to be at the new location.

So when you click edit, the application has 3 seconds to show the edit screen... and when you click save it has 3 seconds to re-arrange itself back to the graph screen. No animations required.

Hope this helps

#17 amandus on 8.24.2009 at 6:47 PM

Hi Alex,

is it possible to get the sources for this tutorial?

I think, this would be very helpful to learn something about visual states, resizing and databinding

Thank you!

#18 tom on 9.04.2009 at 1:03 AM

How did you make that 3D chart...? That should be the next tutorial!

#19 English to Italian translation on 9.30.2009 at 5:09 AM

Thanks for all the useful information. You have been a great help.

#20 Jump Higher on 5.05.2010 at 1:52 AM

Is it possible to get the sources for this tutorial?

I think, this would be very helpful to learn something about visual states, resizing and databinding

Thank you!

#21 vinod on 6.01.2010 at 1:55 PM

Hi,

I am working on Dashboard, I am Designer, Newbie to Silverlight, Working on Blend 4 I want to animate chartseries column graph its current state is when data changes fade in and fade out effect its default, I want to animate column graph as hight increase and decrease effect, How to do in blend 4

#22 Mensagens para Orkut on 9.03.2010 at 7:06 AM

Expression Blend 3 introduces new databinding experience, generating information and plenty of other data-related improvements.

#23 Namibia Safari on 10.10.2010 at 10:22 PM

Easing is a part of animating which allows you to add effects to a simple A to B movement of an object, like a bouncing effect for instance.

#24 tinnitus on 11.14.2010 at 4:01 AM

I really thanks to the author! This is very informative story and great comments.

#25 These facts are amazing .I was searching before last 5 weeks and i dint get the perfect answer.But after all i found from your s on 11.17.2010 at 3:56 AM

http://getinstantpagerank.com/

#26 Backlinks on 11.17.2010 at 4:07 AM

Its very awesome article,all the content is so beneficial and valuable for us.presentation of article is very good,so I will bookmark it for sharing it with my friends.Thanks for sharing nice and pretty post.

#27 Pandora on 12.06.2010 at 2:51 AM

the design will remains in the design owner, but he must give authorization for usage in rubyinstaller.

#28 Zagam2 on 1.06.2011 at 1:14 AM

I click this button go to that state and take 3 seconds to do it. So Silverlight then calculates what it needs to do within those 3 seconds for each item to be at the new location.<a href="http://www.newyorkwebdesign.net" rel="follow">new york web design</a>..Thanks

#29 Zagam2 on 1.06.2011 at 1:20 AM

.Can I copy this article on my blog?If so,please mail me,and we can exchange uesful articles in the future<a href="http://www.newyorkwebdesign.net" rel="follow">new york web design</a>. Thanks

#30 watch online movies free on 2.24.2011 at 10:26 AM

thanks to alex this is nice post.. can i copy your article on your blog..

#31 watch online movies free on 2.24.2011 at 10:26 AM

thanks alex

#32 scratch removal on 4.05.2011 at 4:14 PM

Dashboard of my work, I design, beginner to Silverlight, I have to work on a mixture of animation chartseries four histograms in its current state is that when data changes, fade, and by default, I have to figure out the height of the animation to zoom in and factors such as do Blend4..thanks www.iphoneappsreviews.net

#33 Cigarrillos electronicos on 4.08.2011 at 2:22 AM

The clarity in your post is simply spectacular and i can assume you are an expert on this field. Well with your permission allow me to grab your rss feed to keep up to date with incoming post.

#34 dual saw on 4.28.2011 at 11:09 PM

It works very well on my site, thank you, man.

#35 GHR1000 on 8.08.2011 at 1:58 AM

I like the helpful information you provide for your articles. I will bookmark your weblog and test once more here frequently. I am relatively certain I'll be informed many new stuff proper right here! Good luck for the next!

#36 HerSolution on 8.25.2011 at 5:34 AM

You've aptly utilised the energy of words and phrases. Good article.

#37 jogos de motos on 8.27.2011 at 12:19 PM

The direction of the flow of information in a information binding scenario is controlled by the Mode property of the Binding. In this recipe, we'll look at an example that makes use of all the Mode options & in go, we'll push the information that they enter ourselves to the source.

Until now, the information has flowed from the source to the target (the UI controls). However, it can also flow in the opposite direction, that is, from the target towards the source. This way, not only can information binding help us in displaying information, but also in persisting information.

#38 Directory Scape on 9.07.2011 at 4:56 AM

The clarity of your message is simply amazing, and I suppose you are an expert in this field. Well, with your permission, let me draw your RSS feed to monitor incoming messages

#39 Sytropin on 9.21.2011 at 5:35 AM

Thank you for another fantastic post. The place else may anybody get that type of information in such a perfect method of writing? I have a presentation next week, and I'm at the search for such info.

#40 Sytropin on 9.21.2011 at 5:36 AM

I am really inspired together with your writing abilities as smartly as with the structure for your weblog. Is this a paid theme or did you customize it your self? Anyway keep up the excellent quality writing, it's uncommon to see a nice blog like this one nowadays..

#41 Cricket News Live on 10.12.2011 at 10:18 PM

Silverlight is the best for designers and it is help full for all.

#42 how to become a pilot on 10.19.2011 at 2:58 AM

about this topic, I have been lately in your blog once or twice now. I just wanted to say hi and show my thanks for the information provided.

#43 gold price per ounce us dollars on 10.19.2011 at 11:36 PM

You are so talented in writing. God is really using you in tremendous methods. You are doing a great job! This was a wonderful article.Thank you

#44 Calculette Pret Immobilier on 10.20.2011 at 3:31 AM

I really thank the author! This is the story very informative and great comments.

#45 costume wig on 10.25.2011 at 1:31 AM

Fantastic website. Plenty of helpful info here. I am sending it to a few pals ans also sharing in delicious. And of course, thanks in your effort!

#46 medicalyard.com on 10.26.2011 at 10:26 PM

I thinks Simple Data Binding in Blend 3 is very easy and great techniques,.

#47 costume wigs on 10.31.2011 at 9:46 PM

Hello, i feel that i noticed you visited my website so i got here to "return the want".I am trying to in finding things to enhance my web site!I assume its good enough to use some of your concepts!!

#48 grad school personal statement on 11.03.2011 at 4:30 AM

Most of the user interfaces for typical LOB (line of business) applications are being driven by data in one way or another. Controls might use data from external XML files, databases, or other data sources.

#49 budwadvi on 11.06.2011 at 1:04 AM

Fantastic website. Plenty of helpful info here. I am sending it to a few pals ans also sharing in delicious. And of course, thanks in your effort!

#50 halloween wig on 11.07.2011 at 9:52 PM

The theme in issue is positively a problem for quite a few. Glad I observed some accountable data on exactly the same.

#51 cheap costume wigs on 11.11.2011 at 1:37 AM

Whats up very nice web site!! Man .. Excellent .. Superb .. I will bookmark your blog and take the feeds also…I am happy to seek out a lot of helpful info here within the put up, we'd like work out extra techniques in this regard, thanks for sharing. . . . . .

#52 current silver prices per ounce on 11.14.2011 at 10:58 PM

This is very important site. It is very useful for me. Fantastic article! I thoroughly enjoyed your content …very effectively written.

#53 Clubmz Reviews on 12.02.2011 at 2:09 AM

This information is very interesting, I really enjoyed, I would like get more information about this, because is very beautiful, thanks for sharing...:)

#54 silver value per ounce on 12.06.2011 at 1:56 AM

I am excited to keep track the thing that I used to do. thanks for sharing. impressive page indeed.

#55 Mehr on 12.11.2011 at 11:46 AM

Very nice tutorial. Thanks for sharing. Im new with Silverlight but its great until now :)

#56 school website design companies on 12.14.2011 at 12:34 AM

t exhausting to find knowledgeable individuals on this subject, but you sound like you already know what you are speaking about! Tha

#57 Experts Academy Brendon Burchard on 12.14.2011 at 1:25 AM

i feel that i noticed you visited my website so i got here to "return the want".I am trying to in finding things to enhance my web site!I assume its good enough to use some of your concepts!!

#58 Jason Shaw on 12.22.2011 at 10:54 PM

A great article thanks I'll be coming back for sure.

#59 prolonging ejaculation on 12.23.2011 at 4:03 AM

In fact your inventive writing talents has influenced me a lot.Most of these post are always inspiring and I prefer to read quality articles so I am happy to find many good details here in the post, writing is just fantastic.

#60 india vs australia on 12.23.2011 at 9:40 PM

You got a great blog to say about this subject, and so much knowledge. I think that you know how to make people listen to what you have to say, especially with an issue thats so important. Im glad to know this blog.

#61 Vino on 12.24.2011 at 10:29 PM

Very nice article, exactly what I was looking for.

<a href="http://cooldatingtips.net">dating tips</a>

#62 gold and silver prices 2011 on 12.25.2011 at 11:04 PM

It's really great stuff overall, I just wanted to say thank you. I am looking forward to another great article from your side.

#63 universal garage door remote on 12.27.2011 at 2:01 AM

Collapse the properties panel and try out your slider!

Some other tips and hints with Data Binding

#64 gold price today chart on 12.29.2011 at 9:06 PM

There are very informative stuff which I looking for, I'll bookmark this site for further information, such a great job.

#65 seo rajasthan on 1.01.2012 at 11:22 PM

"I was looking for something like this ,Thank you for posting the great content……I found it quiet interesting, hopefully you will keep posting such blogs…

#66 back pain on 1.02.2012 at 5:08 AM

I bound a slider control so I can easily edit the height of the graph items. First let’s look at how to bind a slider to a rectangle’s height.

#67 nook review on 1.03.2012 at 9:28 AM

Actually your artistic writing abilities has inspired me and lot.These kinds of post are always inspiring and I like to read quality articles so I am happy to get many good points here in the post, writing is just great

#68 Tupperware on 1.04.2012 at 8:19 AM

thank you very much, this is the information I need. I hope this website always gave the information quality.

<a href="http://www.alamandadeltasurya.com">Tupperware</a>

#69 current gold prices per ounce on 1.06.2012 at 4:01 AM

I really like it! I'll always appreciate your brief sharing in this awesome stuffs sincerely, this discussion has put light on this topic.

#70 Training Motivasi on 1.09.2012 at 10:43 PM

Training Motivasi

trainingmotivasi@rocketmail.com http://www.inspiringhouse.com di dunia ini ada beberapa macam tipe orang, ada yang kuat menghadapi tekanan, ada orang yang langsung down jika terkena tekanan. tetapi apakah hal yang saya sebutkan tadi itu adalah faktor penting ? mungkin tiap orang pasti mempunyai jawaban yang berbeda-beda. apapun jawaban anda saya berikan <b><a href="http://www.inspiringhouse.com/">Training Motivasi</a></b> secara cuma-cuma....

#71 Training Motivasi on 1.09.2012 at 10:45 PM

Training Motivasi

trainingmotivasi@rocketmail.com http://www.inspiringhouse.com di dunia ini ada beberapa macam tipe orang, ada yang kuat menghadapi tekanan, ada orang yang langsung down jika terkena tekanan. tetapi apakah hal yang saya sebutkan tadi itu adalah faktor penting ? mungkin tiap orang pasti mempunyai jawaban yang berbeda-beda. apapun jawaban anda saya berikan <b><a href="http://www.inspiringhouse.com/">Training Motivasi</a></b> secara cuma-cuma....

#72 Uss Enterprise on 1.11.2012 at 12:07 PM

thank you very much, this is the information I need. I hope this website always gave the information quality.

#73 Uss Enterprise on 1.11.2012 at 12:07 PM

thank you very much, this is the information I need. I hope this website always gave the information quality.

#74 Wireless alarm kit on 1.15.2012 at 8:33 AM

No matter how well your property is secured with locks, fitting an alarm system will add peace of mind and an additional level of protection to your home.

#75 Coolpix S8200 on 1.17.2012 at 7:33 PM

thanks for the tips of binding data, i hope i can get another tips from this website and increase my coding skill

#76 Boligindretning on 1.18.2012 at 12:47 AM

Great and nice post. Thanks.

#77 modular kitchen on 1.19.2012 at 2:54 AM

It's really great stuff and I look forward to reading your post. What you have to say is important and should be read.

#78 Croatia foto on 1.28.2012 at 1:22 PM

Like this tutorial, helps me a lot...

#79 cell phones and accessories on 1.29.2012 at 8:15 PM

nice data binding info, i will try it soon and those script is not too long, so i will easily remember it

#80 sports and outdoors sports medicine on 2.01.2012 at 5:53 PM

thanks for the data binding script and how to create it steps, i think it will makes it much more easy to try

Leave a Comment