New binding feature of silverlight4beta (Part 2)

Source: Internet
Author: User

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 ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.