あなたはデータバインドImageSource
を持っている場合は、あなたがするときの選択を手動で現在の項目の負荷を強制することは、そのような方法でそれを行うことができますFlipView
が変更されます。
カスタムアイテムクラスを作成できます。 XAMLで
public class FlipViewItemViewModel : INotifyPropertyChanged
{
private bool _isLoaded = false;
private ImageSource _imageSource = null;
public ImageSource ImageSource
{
get
{
return _imageSource;
}
set
{
_imageSource = value;
OnPropertyChanged();
}
}
/// <summary>
/// Forces the loading of the item
/// </summary>
public void ForceLoad()
{
//prevent loading twice
if (!_isLoaded)
{
_isLoaded = true;
//load the image (probably from network?)
ImageSource = new BitmapImage(
new Uri("ms-appx:///Assets/StoreLogo.png"));
}
}
/// <summary>
/// INotifyPropertyChanged implementation
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(
[CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
を、あなたはItemsSource
を使用してFlipView
にデータソースをバインドし、SelectionChanged
イベントを処理する必要があります:イメージがロードされたとき、それはコントロールを通知するように、それはINotifyPropertyChanged
インタフェースを実装することに注意してください
<FlipView x:Name="FlipControl"
ItemsSource="{x:Bind Items}"
SelectionChanged="Selector_OnSelectionChanged">
ハンドブックSelectionChanged
ハンドラの内部で、現在のアイテムのForceLoadメソッドを手動で呼び出します。
private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
//get the currently selected item
var currentItem = FlipControl.SelectedItem as FlipViewItemViewModel;
//force-load it
currentItem?.ForceLoad();
}
GitHub sample with this solution and exampleを作成しました。
私の問題は次のとおりです。 画像を非同期に読み込むカスタムコントロールで構成される項目が含まれているフリップビューを使用しています。私は選択したインデックスのイメージを読み込みたいだけです。したがって、フリップビューが読み込まれると、最初の項目が読み込まれます。ユーザーが左にスワイプすると、2番目の画像が読み込まれます。 – Maximus