我在这里问了同样的问题: Image overlay in a flipview
除此之外,我已将 FlipView.ItemTemplate
绑定(bind)到具有 2 个图像的 UserControl
。
为了能够从 MainPage.xaml.cs 访问绑定(bind)的 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]));
但是如果我以这种方式绑定(bind)图像,即使是 flipView 也不会显示任何内容:
App.Image1 = new BitmapImage(new Uri("ms-appx:///Assets/Images/page0.jpg"));
我应该如何以它们从数组中自动连续生成的方式绑定(bind)它们?
最佳答案
创建一个新类:
public class MyImage
{
public ImageSource Image1 { get; set; }
public ImageSource Image2 { get; set; }
}
在您的页面中,您必须将图像加载为 List<MyImage>
, (如果索引为奇数,则 myImage.Image1 = yourImage,否则 myImage.Image2 = yourImage)
然后,在您的用户控件中,将图像绑定(bind)到 Image1 和 Image2,并将翻转的 ItemsSource 设置为 List<MyImage>
关于c# - 在 FlipView 中绑定(bind) 2 个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29643186/