简体   繁体   中英

Mill Game in Xamarin XAML c# win8

I want to make a Mill Game in Xamarin. I want buttons in specific locations in grid. These locations are coming from my ViewModel like this, but i dont know how to do it after browsing forums.

I want empty spaces or lines between buttons

 <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:view="clr-namespace:Malom.Portable.View" xmlns:controls="clr-namespace:DLToolkit.Forms.Controls;assembly=DLToolkit.Forms.Controls.FlowListView" x:Class="Malom.Portable.View.GamePage"> <ContentPage.Resources> <ResourceDictionary> <Style x:Key="EllipseStyle" TargetType="Button"> <Style.Triggers> <DataTrigger TargetType="Button" Binding="{Binding Color}" Value="BluePlayer"> <Setter Property="BackgroundColor" Value="Blue" /> </DataTrigger> <DataTrigger TargetType="Button" Binding="{Binding Color}" Value="RedPlayer"> <Setter Property="BackgroundColor" Value="Red" /> </DataTrigger> <DataTrigger TargetType="Button" Binding="{Binding Color}" Value="Empty"> <Setter Property="BackgroundColor" Value="Black" /> </DataTrigger> </Style.Triggers> </Style> </ResourceDictionary> </ContentPage.Resources> <Grid> <ListView ItemsSource="{Binding Fields}" HasUnevenRows="True"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <ViewCell.View> <Grid Padding="30,30,30,30" VerticalAlignment="Center"> <Button Grid.Row="{Binding Y}" Grid.Column="{Binding X}" Command="{Binding FieldChangeCommand}"></Button> </Grid> </ViewCell.View> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView> </Grid> </ContentPage> 

you can iterate through your list of Fields and programatically create a button and assign it to your Grid:

foreach(var field in Fields)
{
  myGrid.Children.Add(new Button { Text = field.Name }, field.X, field.Y);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM