3

ControlTemplate で、形を整えたボタンを使用しています。また、controlTemplate にストーリーボードを追加しました。ストーリーボードは、controlTemplate の要素のボーダーを変更します。コードビハインドからこれにアクセスしてアクティブにします。問題は、電話でこれを行うと遅延が発生することです。MVVM構造の後にコードを構造化しました。私の見解は次のとおりです。

 <Button x:Name="Button1" BorderThickness="0" BorderBrush="Transparent">
        <Button.Template>
            <ControlTemplate x:Name="Control">
                <Path x:Name="Control2" Style="{StaticResource style_ColorButton}" Data="{Binding Data}" Fill="{StaticResource Background}">
                    <Path.Resources>
                        <Storyboard x:Name="StoryBoard1">
                            <ColorAnimation Storyboard.TargetName="Control2" Storyboard.TargetProperty="(Stroke).(SolidColorBrush.Color)" To="Blue" Duration="0"/>
                        </Storyboard>
                    </Path.Resources>
                </Path>
            </ControlTemplate> 
        </Button.Template>

そして、ストーリーボードをアクティブにする ViewModel の部分:

   foreach (UIElement x in ElementsAtPoint)
        {
            f = x as FrameworkElement;
            if (f is Path)
            {
                try { 
                h = f as Path;
                Storyboard sb = h.Resources["StoryBoard1"] as Storyboard;
                sb.Begin();
                    }
                catch
                {

                }
                break;
            }
        }

アニメーションに Dependency オブジェクトを使用できることを読みましたが、それがどのように機能するか、または機能するかどうかはわかりませんが、アニメーションに依存オブジェクトを実装しようとする助けがあれば幸いです。

4

1 に答える 1