am new to wpf and C# and mvvm. Currently am working on a Reversi game ,specificaly ui and viewmodel.
In the Vm I currently have setup this hierarchy --> the Vm contains a List of RowVieModels ---> the RowViewModels have a list of SquareViewModels --> each SquareViewModel represent a square on the reversi gameboard.
the thing am stuck on is how can I bind each SquareViewModel to the grid on my xaml ui? The thing I've thought up is to bind each RowViewModel to a row on the grid and from there bind each square but I don't know how to do the binding.
this is the SquareViewModel
class SquareViewModel
{
private ICell<ISquare> square;
public ISquare squareproperty
{
get { return this.square.Value; }
private set { this.square.Value = value; }
}
public SquareViewModel(ISquare square)
{
this.square.Value = square;
}
public Player getOwner()
{
return this.square.Value.Owner.Value;
}
public void zetSteen(Player player)
{
this.square.Value.Owner.Value = player;
}
public bool isValidMove()
{
return this.square.Value.IsValidMove.Value;
}
public Vector2D getPositie()
{
return this.square.Value.Position;
}
}
}
and this is the grid I want to bind to
<DataGrid x:Name="grid" Background="AntiqueWhite" Width="400px" Height="400px" >
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire