簡體   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