簡體   English   中英

在FlipView中綁定2個圖像

[英]Binding 2 images inside 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"));

我應該如何以一種從陣列自動連續生成的方式綁定它們?

創建一個新類:

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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM