c# - 在 FlipView 中绑定(bind) 2 个图像

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

我在这里问了同样的问题: 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/

相关文章:

c# - 如何在 DataTrigger 中使用预定义样式

c# - 如何在Windows应用商店应用程序中获取图像的一个像素(C#)

winforms - 何时使用 Windows 应用商店应用程序?

Windows 商店 - 认证失败,因为 'didn' t 似乎有用'

c# - AsOrdered() 不起作用

c# - 秒表(System.Diagnostics)和 System.Timers

c# - 在 C# 中更改网格的 Canvas.ZIndex

在StackPanel中时,WPF ToolBar Separator缩小为零

c# - 应该定期调用 GC.Collect() 吗?

c# - 打印出方法的返回值