Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no short answer to this question, so I'll give an outline feel free to ask more questions to get more details where needed:</p> <p>To use databinding make sure the items in the collection implement INotifyPropertyChanged. Currently you are using an array of strings. String do not implement INotifyPropertyChanged.</p> <p>Also make sure the collection implements INotifyCollectionChanged. Currently you are using an two dimensional array. An array does not implement this interface.</p> <p>A solution would be to create a class named Tile that implements INotifyPropertyChanged and stores the character as a string and additionally stores its position on the board in an X and Y property:</p> <pre><code>public class Tile : INotifyPropertyChanged { private string character; public string Character { get { return character; } set { if(character != value) { character = value; OnPropertyChanged("Character"); } } } private int x; // repeat for y and Y public int X { get { return x; } set { if(x != value) { x = value; OnPropertyChanged("X"); } } } public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string propertyName) { var p = PropertyChanged; if(p != null) { p(this, new PropertyChangedEventArgs(propertyName)); } } } </code></pre> <p>Create a class Tiles like this:</p> <pre><code>public class Tiles : ObservableCollection&lt;Tile&gt; { } </code></pre> <p>and replace the two dimensional array with this collection.</p> <p>One way of binding an items control to the collection requires you to set the DataContext of the items control to an instance of the collection and specifying the property ItemsSource="{Binding}"</p> <p>Use the Character, X and Y properties in the itemtemplate to display the text and position the tile.</p> <p>This way the bindings will automagically update the view when you manipulate the Tiles collection when adding or removing tiles and the board will also be updated when a tile changes (either position or content)</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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