我是通用应用程序开发的新手,我有一个翻转视图,每个页面有 4 个按钮,每个按钮都有一个图像(总共 8 个图像),我创建了一个模型类,其中包含图像列表及其 URL:
public class SampleItem
{
public string Image1 { get; set; }
public string Image2 { get; set; }
public string Image3 { get; set; }
public string Image4 { get; set; }
public string Image5 { get; set; }
public string Image6 { get; set; }
public string Image7 { get; set; }
public string Image8 { get; set; }
}
public class ButtonImages
{
public List<SampleItem> SampleItems { get; set; }
public ButtonImages()
{
SampleItems = new List<SampleItem>();
SampleItems.Add(new SampleItem()
{
Image1 = "images/1.png"
});
SampleItems.Add(new SampleItem()
{
Image2 = "images/2.png"
});
SampleItems.Add(new SampleItem()
{
Image3 = "images/3.png"
});
...........//all the 8 images URIs
然后我定义了名为flipview1的翻转视图:
<Page.Resources>
<DataTemplate x:Key="FlipViewItemTemplate">
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button Grid.Column="0" Grid.Row="0" >
<Image Source="{Binding Image1}"/>
</Button>
<Button Grid.Column="1" Grid.Row="0">
<Image Source="{Binding Image2}" />
</Button>
<Button Grid.Column="0" Grid.Row="1">
<Image Source="{Binding Image3}"/>
</Button>
<Button Grid.Column="1" Grid.Row="1">
<Image Source="{Binding Image4}"/>
</Button>
</Grid>
</DataTemplate>
</Page.Resources>
<FlipView x:Name="flipView1" ItemTemplate="{StaticResource FlipViewItemTemplate}"/>
这是我尝试获取 8 张图像并将它们放在每 4 个按钮中,在每个页面中:
private void getimages()
{
List<ButtonImages> T = new List<ButtonImages>();
ButtonImages a;
if(true)
{
a = new ButtonImages();
T.Add(a);
}
flipView1.ItemsSource = T;
}
但我得到 8 页,每页有 4 个按钮,在每一页中,一个按钮有一个图像,其他的都是空的 :(
我已经调试了代码,并且我将 T 中的所有图像作为列表获取,请问您知道如何更正代码
感谢帮助