私はユニバーサルアプリの開発に不慣れで、各ページに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つのボタンがあり、各ページには1つのボタンに画像があり、他のボタンは空です:(
コードをデバッグしました。T のすべての画像をリストとして取得しました。コードを修正する方法を教えてください。
手伝ってくれてありがとう