0

他のプロセスからウィンドウの位置をアニメーション化する必要があります。Sine、Quad、Quart、または Back イージングを使用してスムーズなアニメーションでこれを実現する方法はありますか?

4

1 に答える 1

0

WPF について話していると仮定すると、ポジショニング アニメーションとイージング関数は、おそらく xaml ストーリーボード アニメーションで処理するのが最適でしょう。

より大きな問題は、別のプロセスからアプリケーションまたはコントロールを制御することです。両方のアプリケーションのコードがあると仮定すると、ある種のプロセス間通信を実装し、所有プロセスが独自の要素を再配置できるようにする方が簡単です。NamedPipeServerStream と NamedPipeClientStream を使用すると、再配置リクエストを送受信できます。

それ以外の場合は、AutomationPeers を使用して UI の自動化を検討することをお勧めします。

http://msdn.microsoft.com/en-us/library/ms747327(v=VS.85).aspx


アプリケーションで次の xaml を指定します。

<Grid>
    <Button Name="btnOne" Content="this is test button">
        <Button.Style>
            <Style TargetType="Button">
                <Setter Property="Margin" Value="20" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ElementName=PositionCheck,Path=IsChecked}" Value="True" >
                        <Setter Property="Margin" Value="-150,20,150,20" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Button.Style>
    </Button>
    <CheckBox Content="CheckBox" Name="PositionCheck" Visibility="Collapsed" AutomationProperties.AutomationId="chkToggle" VerticalAlignment="Top" />
</Grid>

次のように、別のアプリケーションからボタンをジャンプさせることができます。

        Process p = Process.GetProcessesByName("ProjectWithButton").FirstOrDefault();
        if (p != null)
        {
            AutomationElement ele = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ProcessIdProperty, p.Id));
            if (ele != null)
            {
                AutomationElement chk= ele.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "chkToggle"));
                TogglePattern toggle = chk.GetCurrentPattern(TogglePattern.Pattern) as TogglePattern;
                System.Diagnostics.Debug.WriteLine(toggle.Current.ToggleState);
                toggle.Toggle();
            }
        }

アニメーションを簡単にトリガーしたり、移動用の座標を含む 2 つのテキスト ボックスを作成したりできます。

于 2011-01-27T21:15:38.980 に答える