0

Silverlight でアニメーションをトリガーするカスタム イベントを作成しようとしています。イベントはトリガーされていますが、アニメーションは機能していません。関連するコードは次のとおりです。

namespace SilverlightApplication1
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            MyEvent += new ChangedEventHandler(UserControl_MyEventHandler);
            /* Other stuff */
        }
        private void UserControl_MyEventHandler(object sender, RoutedEventArgs e)
        {
                MessageBox.Show("MyEventHandler has been called");
        }

        public delegate void ChangedEventHandler(object sender, RoutedEventArgs e);

        private event ChangedEventHandler MyEvent;

        private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
                if (MyEvent != null)
                    MyEvent(this, e);
        }
    }
}

XAML コードは次のとおりです。

<UserControl
... 
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" mc:Ignorable="d"
x:Class="SilverlightApplication1.MainPage" MouseLeftButtonDown="UserControl_MouseLeftButtonDown">

    <Grid x:Name="LayoutRoot" Background="White">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="MyEvent">
                <ei:GoToStateAction StateName="Highlighted"/>
            </i:EventTrigger>
        </i:Interaction.Triggers>
        ...
    </Grid>
</UserControl>

現在、「MouseLeftButtonDown」を含むメッセージ ボックスは表示されていますが、アニメーションは呼び出されていません。EventTrigger EventName がMouseLeftButtonDownではなく、アニメーションが呼び出されましたMyEvent。私を助けてください。ありがとう。

4

1 に答える 1

0

何らかのコントロールのイベントでトリガーする場合は、EventTrigger に SourceName を設定できます。あなたの場合、コードの背後にあると思います:

VisualStateManager.GoToState(this [or some other object with Highlighted state], "Highlighted", false);
于 2011-08-27T13:38:05.903 に答える