0

Expression Blend(SketchFlow)を使用して非常に簡単なことをしたいと思います。

画面にボタンを3秒以上押すと、別の画面に移動するボタンが欲しいのですが。

私はこれを使うことを考えました(緑色の答え): ボタンロングクリック

MouseLeftButtonDown内ですが、c#コードを使用して別の画面に変更する方法がわかりません...[移動先]オプションを設定するだけです。

したがって、ボタンにロングクリック動作を設定して新しい画面に変更する方法を誰かに教えてもらえれば、それは素晴らしいことです。

4

1 に答える 1

1

使用できる類似しているがより単純なクラスは次のとおりです。

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Interactivity;
using System.Windows.Threading;

namespace SilverlightApplication14
{
    public class LongClickButton : Button
    {
        public event EventHandler LongClick;

        public static DependencyProperty HowLongProperty = DependencyProperty.Register("HowLong", typeof(double), typeof(LongClickButton), new PropertyMetadata(3000.0));

        public double HowLong
        {
            get
            {
                return (double)this.GetValue(HowLongProperty);
            }
            set
            {
                this.SetValue(HowLongProperty, value);
            }
        }

        private DispatcherTimer timer;

        public LongClickButton()
        {
            this.timer = new DispatcherTimer();
            this.timer.Tick += new EventHandler(timer_Tick);
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            this.timer.Stop();
            // Timer elapsed while button was down, fire long click event.
            if (this.LongClick != null)
            {
                this.LongClick(this, EventArgs.Empty);
            }
        }

        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);
            this.timer.Interval = TimeSpan.FromMilliseconds(this.HowLong);
            this.timer.Start();
        }

        protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonUp(e);
            this.timer.Stop();
        }
    }

}

これにより、新しいLongClickイベントとともに、Blendの標準的な動作を使用できます。HowLongプロパティを必要なミリ秒数(デフォルトは3000)に設定してから、LongClickに設定されたeventtriggerを使用してナビゲーションをトリガーします。

<local:LongClickButton Margin="296,170,78,91">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="LongClick">
                <ei:ChangePropertyAction PropertyName="Background" TargetName="LayoutRoot">
                    <ei:ChangePropertyAction.Value>
                        <SolidColorBrush Color="#FFFF1C1C"/>
                    </ei:ChangePropertyAction.Value>
                </ei:ChangePropertyAction>
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </local:LongClickButton>
于 2011-11-28T16:27:40.930 に答える