Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since you cant easily Bind the Row/Column definitions of a <em>Grid</em>, i suggest you to build a simple custom control, which inherits directly from <em>Grid</em>.</p> <p>Here is my approach with 3 additional dependency properties:</p> <ul> <li>int MyColumnCount</li> <li>int MyRowCount</li> <li>ObservableCollection MyChilds</li> </ul> <p>the MyColumnCount/MyRowCount will be bound to Properties in the ViewModel, which you update, when you get the new values from the database. Also the ViewModel will provide a collection of FrameworkElements, which will be the items in the Grid and is bound to MyChilds.</p> <p>You can create new Controls in the ViewModel and use the attached property of the Grid, to set the Position. For example:</p> <pre><code>TextBlock b = new TextBlock() { Text = "Hello World!" }; Grid.SetRow(b, &lt;your position&gt;); Grid.SetColumn(b, &lt;your position&gt;); Grid.SetColumnSpan(b, &lt;your column span&gt;); MyChilds.Add(b); </code></pre> <p>In the <em>PropertyChangedCallbacks</em> of the new <em>int</em> properties, you modify the Row/Column definitions, according to the new values. The callback of the collection property registers a collection changed event on the new ObservableCollection and adds the new items to the Grid's children, on changing events.</p> <p>Thats all you need for the dynamic grid changes.</p> <p>To your second question: This is quite easy. In the event you catch you will get the sender of the clicked item in the grid. The sender is mostly the direct clicked control. You can use the static Grid functions again, to calculate the position:</p> <pre><code>Grid.GetRow(item); Grid.GetColumn(item); Grid.GetColumnSpan(item); </code></pre> <p>With the total number of rows/columns of the grid (My...Count) you can calculate neighbor positions.</p> <p>Jan</p>
    singulars
    1. This table or related slice is empty.
    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