About DATAbinding,How to Binding a temporary object's properties to a INT array[] in C#?

ClawRageClawRage Member ✭✭
edited April 1 in Xamarin.Forms

我的程式預計要在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?

Best Answers

Answers

  • ClawRageClawRage Member ✭✭
    edited April 1

    Thanks for your enthusiasm.
    This is first time I heard about observable collection ,
    I will studding about it.
     

  • ClawRageClawRage Member ✭✭
    edited April 1

    this is just a wrong reply

  • LandLuLandLu Member, Xamarin Team Xamurai

    @ClawRage Hi, do you have any update?

  • ClawRageClawRage Member ✭✭
    edited April 3

    在我嘗試ListView之前,我先暫時將物件整個排入陣列中配合Array.Resize()控制範圍,用這個方法規避臨時創建的物件無法指定的盲點(但實際上更新資料的方式仍是一次次在迴圈手動更改),希望這幾天掌握了ListView後能捨棄這原始的手段。

    Before attempt grasp LiveView,I use this way integrated send Objects to Object-type array with update range by Array.Resize(), to avoid the problem CODE can't specify that object just built in C#.(However,This way is not use Binding),Hope that after hold the ListView these days, I can abandon this primitive tick.

Sign In or Register to comment.