Hi all,
I'm employing the FluidKit.dll into my application to get a nice slide in/out transition effect for my windows, pages and usercontrols. Now I have it working, however it seems that the animations start getting a little jerky when there is more information on a transitioning page. I've read a little and it seems that I can aid in the fluidity of the transitions by implementing the RenderTargetBitmap functionality in my content presenter.
Does anyone know how to do this or have a good pointer for me? Below is the code I'm using for the ContentPresenter:
public class NavigationPresenter : ContentPresenter
{
private readonly ContentPresenter oldContentPresenter;
private readonly ContentPresenter newContentPresenter;
private readonly TransitionPresenter transitionPresenter;
private bool loaded;
#region GoForward
public static readonly DependencyProperty GoForwardProperty;
public bool GoForward
{
get { return (bool)GetValue(GoForwardProperty); }
set { SetValue(GoForwardProperty, value); }
}
#endregion
#region Transition
public static readonly DependencyProperty TransitionProperty;
public Transition Transition
{
get { return (Transition)GetValue(TransitionProperty); }
set { SetValue(TransitionProperty, value); }
}
#endregion
internal UIElementCollection Children
{
get;
private set;
}
static NavigationPresenter()
{
GoForwardProperty = DependencyProperty.Register(
"GoForward",
typeof(bool),
typeof(NavigationPresenter),
new FrameworkPropertyMetadata(false));
TransitionProperty = DependencyProperty.Register(
"Transition",
typeof(Transition),
typeof(NavigationPresenter),
new FrameworkPropertyMetadata(new NavigationCubeTransition(), new PropertyChangedCallback(OnTransitionChanged)));
ContentProperty.OverrideMetadata(
typeof(NavigationPresenter),
new FrameworkPropertyMetadata(null, new PropertyChangedCallback(OnContentValueChanged)));
}
public NavigationPresenter()
{
this.oldContentPresenter = new ContentPresenter();
this.newContentPresenter = new ContentPresenter();
this.transitionPresenter = new TransitionPresenter();
this.transitionPresenter.Items.Add(this.oldContentPresenter);
this.transitionPresenter.Items.Add(this.newContentPresenter);
this.Children = new UIElementCollection(this, null);
this.Children.Add(this.transitionPresenter);
this.Loaded += (s, e) => this.loaded = true;
}
private static void OnTransitionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((NavigationPresenter)d).OnTransitionChanged(e);
}
private static void OnContentValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((NavigationPresenter)d).OnContentValueChanged(e);
}
private void OnContentValueChanged(DependencyPropertyChangedEventArgs e)
{
this.oldContentPresenter.Content = e.OldValue;
this.newContentPresenter.Content = e.NewValue;
if (this.loaded)
{
if (this.transitionPresenter.Transition is INavigationAware)
{
if (this.GoForward)
((INavigationAware)this.transitionPresenter.Transition).GoForward();
else
((INavigationAware)this.transitionPresenter.Transition).GoBackward();
}
this.transitionPresenter.ApplyTransition(this.oldContentPresenter, this.newContentPresenter);
}
}
private void OnTransitionChanged(DependencyPropertyChangedEventArgs e)
{
this.transitionPresenter.Transition = e.NewValue as Transition;
}
protected override Visual GetVisualChild(int index)
{
if ((index < 0) || (index >= this.Children.Count))
throw new ArgumentOutOfRangeException("index");
return this.Children[index];
}
protected override int VisualChildrenCount
{
get
{
if (this.Children != null)
return this.Children.Count;
else
return 0;
}
}
}
I may be completely misunderstanding the implementation of RenderTargetBitmap, so if it's not the ContentPresenter that should utilize it then where would be best? Or if you have any better recommendations then that's great.
Kind regards,
Jib