Best away to animate the position of the window from another process, with Sine easing?

532 views Asked by At

I need to animate the position of windows from other processes. Is there any way to achieve this with smooth animations using Sine, Quad, Quart, or even Back easing?

1

There are 1 answers

3
bigtlb On

Assuming you are talking about WPF, then the positioning animation and easing functions would probably be best handled with xaml storyboard animation.

The bigger question would be getting control of the applicaton or controls from another process. Assuming you have code for both applications it would be easier to implement some sort of interprocess communication and let the owning process reposition it's own elements. NamedPipeServerStream and NamedPipeClientStream would let you send/receive a reposition request.

Otherwise, you might want to look into UI automation through AutomationPeers.

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


Give the following xaml in an application:

<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>

You can make the button jump around from another application like this:

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

You could just as easily trigger animations, or have two text boxes with coordinates for movement.