Silverlight-可視元件相互繫結(using System.Windows.Data.Binding)
1: using System.Windows.Data;
2:
3: namespace Object_Binding
4: {
5: public partial class MainPage : UserControl
6: {
7: public MainPage()
8: {
9: InitializeComponent();
10: //定義一個繫結元件(rectWidthBinding)
11: //資料來源是silder1的屬性Value
12: Binding rectWidthBinding = new Binding("Value");
13: rectWidthBinding.Source = slider1;
14: //透過rectangle1的方法(SetBinding)對屬性(WidthProperty、HeightProperty)
15: //進行資料繫結
16: rectangle1.SetBinding(Rectangle.WidthProperty, rectWidthBinding);
17: rectangle1.SetBinding(Rectangle.HeightProperty, rectWidthBinding);
18: }
19: }
20: }