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();
            }
        }

您可以很容易地触发动画,或者有两个带有移动坐标的文本框。

于 2011-01-27T21:15:38.980 回答