在FlipView中绑定2个图像

时间:2015-04-15 06:37:13

标签: c# xaml windows-store-apps windows-8.1 flipview

我在这里问了同样的问题: Image overlay in a flipview

除此之外,我已将FlipView.ItemTemplate绑定到包含2张图片的UserControl。 为了能够从MainPage.xaml.cs访问绑定的ImageSource,我在App.xaml.cs中创建了2个全局变量:

public static ImageSource Image1 { get; set; }
public static ImageSource Image2 { get; set; }

public static new App Current
{
    get { return Application.Current as App; }
}

我可以这样设置第一张图片:

flipView.Items.Add(new Uri(BaseUri, Images[0]));

但如果我以这种方式绑定图像,即使是flipView:

也不会显示任何内容
App.Image1 = new BitmapImage(new Uri("ms-appx:///Assets/Images/page0.jpg"));

我应该如何以自动生成的方式绑定它们&连续从阵列?

1 个答案:

答案 0 :(得分:0)

创建一个新类:

public class MyImage
{
     public ImageSource Image1 { get; set; }
     public ImageSource Image2 { get; set; }
}

在你的页面中,你必须将图像加载为List<MyImage>,(如果索引是奇数,myImage.Image1 = yourImage,否则myImage.Image2 = yourImage)

然后,在您的用户控件中,将图像绑定到Image1和Image2,并将翻转的ItemsSource设置为List<MyImage>

相关问题