Skip to content

Instantly share code, notes, and snippets.

@meron1122
Created June 2, 2018 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meron1122/bb2bee5136c15b86eb21837ee0a684a9 to your computer and use it in GitHub Desktop.
Save meron1122/bb2bee5136c15b86eb21837ee0a684a9 to your computer and use it in GitHub Desktop.
namespace StrategoGUI
{
public class GameField
{
public Players Player { get; set; } = Players.Nobody;
public GameField(CellLocation location)
{
Location = location;
}
}
public enum Players
{
Nobody,
Player,
Computer
}
}
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:StrategoGUI"
Width="{Binding Width}"
Height="{Binding Height}"
Title="GameWindow">
<Window.Styles >
<Style Selector="ItemsControl > ContentPresenter">
<Setter Property="Canvas.Left" Value="{Binding Location.X}"/>
<Setter Property="Canvas.Top" Value="{Binding Location.Y}"/>
</Style>
</Window.Styles>
<ItemsControl
Items="{Binding GameFields}" <!-- collection of classes show above -->
Width="{Binding Width}"
Height="{Binding Height}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.DataTemplates>
<DataTemplate DataType="{x:Type local:GameField }"> <!-- if( Elem.Player == Players.Nobody , and another enum vals analogus-->
<Image Width="64" Height="64" Source="resm:StrategoGUI.Resources.empty.png" />
</DataTemplate>
</ItemsControl.DataTemplates>
</ItemsControl>
</Window>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment