Binding can be a source of control (control is a Source of another control, control their own container as a Source), Source of the collection as ItemsControls, the xml as a Tree, or Menu of Source, Source or do not give it, let him find their own.
- A control to another control Source
<TextBox x:Name="textBox" Text="{Binding Value,ElementName=slider1}" BorderBrush="Black" Margin="5"/> <Slider x:Name="slider1" Maximum="100" Minimum="0" Margin="5"/>
这是两个控件Slider是TextBox的Source
Here is the xaml Binding by the language setting, here is the Binding markup extension syntax. C # is equivalent to the statement
this.textBox1.SetBinding (TextBox.TextProperty, the Binding new new ( "the Value") = {ElementName "Slider1"});
(equivalent to the Text TextBox.TextProperty; (This is the Target) Binding Value. = new Binding ( "Value" (this is the Path (Slide1 properties)). ElementName this is the source)
- Path
Binding Path supports multi-level paths, such as the above access Path is the Value property, then Path following secondary path.
Binding path can also indexer to Path as, for example: Path is above attribute Value (if this is a collection of Value), it may be a Path Value [. 1] to obtain a second set of object
Binding path syntax can also shaded to find a multi-stage multi-level directory needed Path, chestnuts corresponding follows:
class City { public string Name { get; set; } } class Province { public string Name { get; set; } public List<City> CityList { get; set; } } class Country { public string Name { get; set; } public List<Province> ProvinceList { get; set; } } List<Country> countryList=new List<Country>{new Country(){Name="中国"}}; List<string> List=new List<string>(){"Tim","Tom","Blog"}; this.textBox1.SetBinding(TextBox.TextProperty,new Binding("/"){Source=List}); this.textBox2.SetBinding(TextBox.TextProperty,new Binding("/Length") {Source=List,Mode=BindingMode.OneWay}); this.textBox3.SetBinding(TextBox.TextProperty,new Binding("/[2]") {Source=List,Mode=BindingMode.OneWay});
- Without the Binding Path (Binding data source itself, such as the Resource in the text, or some not belong to any object value) as follows, as chestnuts
<StackPanel.Resources>
<sys:String x:Key="myString">
不带Path的Binding
</sys:String>
</StackPanel.Resources><TextBlock x:Name="textBlock1" TextWrapping="Wrap" Text="{Binding Path=.,Source={StaticResource ResourceKey=myString}}" FontSize="16" Margin="5"/>