Skip to content

SwitchPanel

ElbyFross edited this page Dec 21, 2019 · 5 revisions

Remarks

The view that provides the API for management child panels. Provides a collection of switch animations. Controls attachment \ detachment of panels from UI for optimisation of performance.

  • Waits till the element will loaded before start switch.

Example

The following code show and example where we will manage the two panales via the SwitchPanel.

In that example we should mean that you have some UserControl panles that would be operated by the switcher. Also we skip the code relative to the declaration, initialization, and management the panels order. You could find an example project by this link.

Defining a SwitchPanel at a xaml file of the example control.

  • Define a name of the control to get access from the code behind.
  • Binding the FormsAnimationDuration property that will define the duration of an panels switch animation.

Defining a Button that will call switch to the next panel.

XAML

<wpfh:SwitchPanel x:Name="switchPanel"
                  Duration="{Binding FormsAnimationDuration}"/>

<Button Content="Next panel"
        Click="NextPanelButton_Click"/>

Declaring and initializing the FormsAnimationDuration property at the code behind.

C#

// How many time will take swich animation of forms.
public TimeSpan FormsAnimationDuration { get; set; }

// Property that contains the refernec to
// the current active panel.
public UserControl CurrentPanel {get; protected set; }

Declaring a costructor and subscribing on the

public SwitchPanleExample()
{
    Loaded += delegate()
    {
        // Set the animation duration to the switch panle property.
        FormsAnimationDuration  = new TimeSpan(0, 0, 0, 0, 300);
    }
}

Declaring the callback to the "Next panel" button. Requesting switch into that handler.

// Occurs when the "next panel" button declared at the xaml clicked.
private void NextPanelButton_Click(object sender, RoutedEventArgs e)
{
     // Set yout code to define what a next panel here.
     ...    

     // Requiesting swith to the next panel.
     // Using an "Alpha swipe animation.
     switchPanel.SwitchTo(CurrentPanel, SwitchPanel.AnimationType.AlphaSwipe);
}

Links

Projects

Relative pages