繁体   English   中英

Xamarin XAML c#win8中的Mill游戏

[英]Mill Game in Xamarin XAML c# win8

我想在Xamarin中进行Mill游戏。 我想要按钮在网格中的特定位置。 这些位置来自这样的ViewModel,但是浏览论坛后我不知道该怎么做。

我想要按钮之间有空格或线条

 <?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> 

您可以遍历字段列表并以编程方式创建一个按钮并将其分配给网格:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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