Note that there are some explanatory texts on larger screens.

plurals
  1. POHow Do I bind a button Content with a list of numbers in WP8?
    primarykey
    data
    text
    <p>At first let me tell you, what I want to achieve. I want that when a windows page loads it will create a lot of buttons, say 10 buttons now at run time I want this <code>Button.Content</code> to Bind with some listvalues, which is a list of 10 numbers. </p> <p><code>public List&lt;int&gt; listvalues = new list&lt;int&gt;();</code></p> <p>I want to do this in MVVM, so my approach is in model I have <code>public int ListNumbers</code> property, with <code>OnPropertyChanged</code> event is defined. Now in the view Model, how do I fill a list <code>listvalues</code> with some 10 integer values(Exactly new to MVVM that's why I am asking). This Ten values will be used for the Content of the 10 Buttons that are run time generated. And after filling the <code>listvalues</code>in the <code>MainPage_Loaded</code> Method of the MainPage how do bind the Content of the Button with the <code>listvalues</code> . </p> <p>To better understand my requirement...</p> <p>I have below XAMl code </p> <p><code>&lt;Canvas x:Name="GameCanvas" Background="Bisque" Height="480" Width="480" /&gt;</code> in <code>MainPage.xaml</code></p> <p>So in the code behind </p> <pre><code>int locationFirst = 25; int locationSecond = 100; char SeatValue = 'A'; int row = 3; int column = 3; public GamePage() { InitializeComponent(); for (int x = 1; x &lt;= row; x++) { for (int i = 1; i &lt;= column; i++) { CreateButtons(SeatValue.ToString() + i, locationFirst, locationSecond); locationFirst = locationFirst + 130; } locationFirst = 25; locationSecond = locationSecond + 50; } } </code></pre> <p>The createButtons code is </p> <pre><code>Button btnNew = new Button(); btnNew.Name = btnName; btnNew.Margin = new Thickness(btnPointFirst, btnPointSecond, 0, 0); btnNew.Width = 100; btnNew.Height = 70; GameCanvas.Children.Add(btnNew); </code></pre> <p>In the Windows Phone I found an issue, is that there is no btnNew.Location(X,Y);</p> <p>So at run time I have to use <code>btnNew.Margin = new Thickness(btnPointFirst, btnPointSecond, 0, 0);</code> which is not putting the buttons in the desired location. However this is my code now how do I assign btnNew.Content with the <code>listNumbers</code> value? </p> <p>Please help. </p> <p>Any link or any elaborate answer is fine for me...</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload