1

アプリWP8用のシンプルなカスタムflipViewを作成しましたが、これは正常に機能しますが、矢印なしで画像を変更するスワイプジェスチャを与える方法がわかりません。 WP8 ):

namespace PhoneApp1
{
public partial class FlipView : UserControl
{
    public FlipView()
    {
        InitializeComponent();
        Datasource = new List<object>();
        SelectedIndex = 0;
    }

    private IList Datasource;
    public static readonly DependencyProperty ItemTemplateProperty =
        DependencyProperty.Register("ItemTemplate", typeof(DataTemplate), typeof(FlipView), new   PropertyMetadata(default(DataTemplate)));

    public DataTemplate ItemTemplate
    {
        get { return (DataTemplate)GetValue(ItemTemplateProperty); }
        set
        {
            SetValue(ItemTemplateProperty, value);
            contentPresenter.ContentTemplate = value;
            contentPresenter.Content = SelectedItem;
        }
    }

    public static readonly DependencyProperty ItemsSourceProperty =
       DependencyProperty.Register("ItemsSource", typeof(IList), typeof(FlipView), new PropertyMetadata(default(IList)));

    public IList ItemsSource
    {
        get { return (IList)GetValue(ItemsSourceProperty); }
        set
        {
            SetValue(ItemsSourceProperty, value);
            Datasource = value;
            SelectedIndex = SelectedIndex;
        }
    }

    public static readonly DependencyProperty SelectedIndexProperty =
        DependencyProperty.Register("SelectedIndex", typeof(int), typeof(FlipView), new PropertyMetadata(default(int)));

    public int SelectedIndex
    {
        get { return (int)GetValue(SelectedIndexProperty); }
        set
        {
            SetValue(SelectedIndexProperty, value);

            rightButton.Visibility = leftButton.Visibility = Visibility.Visible;
            if (SelectedIndex == 0)
            {
                leftButton.Visibility = Visibility.Collapsed;
            }

            if (SelectedIndex + 1 == Datasource.Count)
            {
                rightButton.Visibility = Visibility.Collapsed;
                SelectedItem = Datasource[SelectedIndex];
            }

            if (Datasource.Count > SelectedIndex + 1)
            {
                SelectedItem = Datasource[SelectedIndex];
            }
        }
    }

    public static readonly DependencyProperty SelectedItemProperty =
        DependencyProperty.Register("SelectedItem", typeof(object), typeof(FlipView), new PropertyMetadata(default(object)));

    public object SelectedItem
    {
        get { return (object)GetValue(SelectedItemProperty); }
        set
        {
            SetValue(SelectedItemProperty, value);
            contentPresenter.Content = SelectedItem;
        }
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        SelectedIndex--;
    }

    private void Button_Click_1(object sender, RoutedEventArgs e)
    {
        SelectedIndex++;
    }
}
}

このカスタム フリップビューにスワイプ ジェスチャを与えるベスト プラクティスは何ですか? (ちなみに、私はC#開発の初心者です)

4

1 に答える 1

1

NuGet を使用するか、Web サイトThe Windows Phone Toolkitにアクセスして、Windows Pone Toolkit を入手します。

次に<toolkit:GestureService.GestureListener>、スワイプを検出するコントロールで次のように使用できます。

<Image Source="/Assets/AlignmentGrid.png">
    <toolkit:GestureService.GestureListener>
        <toolkit:GestureListener Flick="OnFlick"></toolkit:GestureListener>
    </toolkit:GestureService.GestureListener>
</Image>
private void OnFlick(object sender, FlickGestureEventArgs e)
{
    double swipe_velocity = 1000;

    // User flicked towards left
    if (e.HorizontalVelocity < -swipe_velocity)
    {
        // Load the next image 
    }

    // User flicked towards right
    if (e.HorizontalVelocity > swipe_velocity)
    {
        // Load the previous image
    }
}

swipe_velocity を快適な値に変更できます。

ツールキットがなければ、XNA を使用するか、3 つのイベントを使用する必要があります

ManipulationCompleted
ManipulationDelta
ManipulationStarted

あなたのジェスチャーを計算します。

于 2014-10-31T01:34:45.283 に答える