Dependencyobject supports binding
In versions earlier than silverlight4, only frameworkelement supports data binding. The following scenarios are not allowed:
<Canvas Width="100" Height="100" RenderTransformOrigin="0.5, 0.5" Background="#FF2B6092"> <Canvas.RenderTransform> <RotateTransform Angle="{Binding ElementName=slider, Path=Value}" /> </Canvas.RenderTransform></Canvas><Slider x:Name="slider" Height="20" Margin="0,225,0,55" Minimum="0" Maximum="360" />
Rotatetransform is certainly not a frameworkelement, and this scenario is so classic. Sl4 makes us ready
Supports string index binding.
Sl4beta supports binding collection items through string indexes. This means that we can easily bind a dictionary object or a set of custom types that provide string indexes.
For example, define an object class:
public class Employee : INotifyPropertyChanged { private Dictionary<string, Object> _customProps; public Dictionary<string, Object> CustomProperties { get { if (_customProps == null) _customProps = new Dictionary<string, object>(); return _customProps; } }}
Set Data Context
var emp = new Employee() { FirstName = "John" };emp.CustomProperties.Add("Nickname", "Johnny");this.DataContext = emp;
Bind by string Index
<TextBox Text="{Binding Path=CustomProperties[Nickname]}"/>
New constructor of observablecollection
Observablecollection is very powerful (but it seems to be too long). It is a common operation to convert list <t> to observablecollection <t> and then bind it. In sl4, we can simplify this process through an overload of the constructor of observablecollection.
List<string> ColorList = new List<string> { "red", "blue", "yellow" };var ColorOC = new ObservableCollection<string>(ColorList);
In additionIdataerrorinfoAndInotifydataerrorinfoThese two new verification-related interfaces are to be described separately in an article.
OK, have fun ~