Learn Fundamentals of Silverlight 4 Data Binding
I'm just starting to work with Silverlight (no WPF experience either) and am having a difficult time finding a source that provides a full explanation of Data Binding. There is absolutely no lack of tutorials (starting with the ones on Silverlight.net or Scott Gu's blogs), but everything I have found is "by example".
Is there a resource that explains how data binding works in Silverlight, from a Fundamental/Conceptual perspective, and provides end-to-end coverage of data binding features?
The desire for a more fundamental source of information is driven by a number of questions that came up this afternoon in reviewing tutorials and writing sample apps, such as:
Silverlight's data binding engine is very similar to WPF's. A decent overview is here http://msdn.microsoft.com/en-us/library/ms752347.aspx.
To answer your specific questions:
You should be able to do that. I just created a little project in Blend to try this out, and it worked great. One bit of trickiness there is the data binding engine is actually internally converting between double and int for you (as Slider.Value is a double).
DataContext is used for setting the context for any binding expressions below that element in the tree. A path is relative to the DataContext by default. For example, if you set your DataContext on your root element to itself using DataContext="{Binding RelativeSource={RelativeSource Self}}"
, then you could add something like <TextBlock Text="{Binding Width}" />
, to add a TextBlock which shows the width of the root element. Path is just an implicit argument, so you could do "{Binding Path=Width}"
, and it would do the same thing.
A Relative Source allows you to choose to not use the DataContext, but instead some other source, like yourself in {RelativeSource Self}.
上一篇: Silverlight内存泄漏