我将fluidmovebehavior设置为Listbox:
<ItemsPanelTemplate>
<StackPanel HorizontalAlignment="Stretch">
<i:Interaction.Behaviors>
<ilayout:FluidMoveBehavior AppliesTo="Children" Duration="0:0:0.3">
<ilayout:FluidMoveBehavior.EaseY>
<ExponentialEase EasingMode="EaseOut" />
</ilayout:FluidMoveBehavior.EaseY>
</ilayout:FluidMoveBehavior>
</i:Interaction.Behaviors>
</StackPanel>
</ItemsPanelTemplate>
列表框放在MainPage.xaml上,并将一些List作为ItemsSource。动画工作正常,但是当我导航到新页面时(无论是哪个页面,甚至是空白页面),我都会收到System.ArgumentException。然后我评论了所有xaml代码 ItemsPanelTemplate ,即关闭Fluid动画。然后导航工作正常。
堆栈跟踪:
System.Windows.ni.dll!MS.Internal.XcpImports.MethodEx(System.IntPtr ptr, string name, MS.Internal.CValue[] cvData)
System.Windows.ni.dll!MS.Internal.XcpImports.MethodPack(System.IntPtr objectPtr, string methodName, object[] rawData)
System.Windows.ni.dll!MS.Internal.XcpImports.UIElement_TransformToVisual(System.Windows.UIElement element, System.Windows.UIElement visual)
System.Windows.ni.dll!System.Windows.UIElement.TransformToVisual(System.Windows.UIElement visual)
microsoft.expression.interactions.DLL!Microsoft.Expression.Interactivity.Layout.FluidMoveBehaviorBase.TranslateRect(System.Windows.Rect rect, System.Windows.FrameworkElement from, System.Windows.FrameworkElement to)
microsoft.expression.interactions.DLL!Microsoft.Expression.Interactivity.Layout.FluidMoveBehaviorBase.UpdateLayoutTransition(System.Windows.FrameworkElement child)
microsoft.expression.interactions.DLL!Microsoft.Expression.Interactivity.Layout.FluidMoveBehaviorBase.AssociatedObject_LayoutUpdated(object sender, System.EventArgs e)
System.Windows.ni.dll!System.Windows.FrameworkElement.OnLayoutUpdated(object sender, System.EventArgs e)
System.Windows.ni.dll!MS.Internal.JoltHelper.RaiseEvent(System.IntPtr target, uint eventId, System.IntPtr coreEventArgs, uint eventArgsTypeIndex)
ADD:如果我设置为listbox.ItemsSource = null,则在导航到其他页面之前,不会发生异常。
我做错了什么?
对不起我的坏言辞。
答案 0 :(得分:0)
我找到了一个可接受的解决方案。
从某个页面导航到上一页后附加行为(如果使用GoBack()方法导航)
private void ChangeBehaviorState<T>(DependencyObject owner, BehaviorState state) where T : DependencyObject
{
DependencyObject root = UIHelper.FindChildOfType<T>(owner);
if (root == null) return;
FluidMoveBehavior b = Interaction.GetBehaviors(root)[0] as FluidMoveBehavior;
if (b == null) return;
switch (state)
{
case BehaviorState.Attach:
b.Attach(root);
break;
case BehaviorState.Detach:
b.Detach();
break;
}
}
BehaviorState,UIHelper - 支持的自定义类。
root - 它是某个类ListBox或其他具有
的UIElement
行为。