我想在Xamarin製造磨機遊戲。我想要網格中特定位置的按鈕。這些位置來自我的ViewModel這樣,但我不知道如何做到這一點後瀏覽論壇。Xamarin XAML磨機遊戲c#win8
我想按鈕
<?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>
如果你想在網格中的特定位置使用按鈕,請不要將它們放在ListView中。以編程方式將它們直接放入網格中。 – Jason
我如何給我的網格項目源?或者我應該使用另一個物品容器?我希望我的按鈕在遊戲 – szarkabarna
等特定位置不能綁定到網格 - 這就是爲什麼我說你必須以編程方式分配按鈕 – Jason