我的程式預計要在C#中以迴圈創造數個物件,並將他們的Text依序綁到一個全域的整數陣列中,用以顯示陣列中隨時變化的數值
如此:
My Project want to creat Buttons in C#,and Binding their Text to the Target array[] to display it's number
Like this:
int target[100]=0;
void CreatButton()
{
for (int i = 1; i <= N; i++)
{
StackLaout_Hello.Children.Add( TheButton(i) );
}
}
以及 and
Button TheButton(int i)
{
Button B
{
BindingContext=??? ///???
text=??? ///???
};
B.SetBinding( Label.TextProperty , new Binding ( Source=target[i+1] ); ///???
return B;
}
我發現我若使用 setBinding 的方式來綁定的話,只有在執行 setBinding 這一行程式時才會更新一次目標數值,是不是我的綁訂條件出了點差錯,最好直接是定BindingContext的條件?
I Found a problem that if I use the code setBinding(QQQ,XXX) to Binding,it will be update Button'text only once when Run this Line,is my Binding code wrong somewhere?or should I set the BindingContext and Text properties Button?