【问题标题】:Trouble with FluidMoveBehavior and Navigation (WP 8)FluidMoveBehavior 和导航问题 (WP 8)
【发布时间】:2014-01-27 19:17:40
【问题描述】:

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

Listbox 放置在 MainPage.xaml 中,并有一些 List 作为 ItemsSource。动画工作正常,但是当我导航到新页面(无论是哪个页面,甚至是空白页面)时,我都会得到 System.ArgumentException。然后我评论了所有 xaml 代码 ItemsPanelTemplate ,即关闭流体动画。然后导航工作正常。

堆栈跟踪:

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)

添加:如果我设置为 listbox.ItemsSource = null ,在导航到另一个页面之前,不会发生异常。

我做错了什么?

对不起,我的语言不好)。

【问题讨论】:

    标签: c# windows-phone-8 listbox


    【解决方案1】:

    我找到了一种可接受的解决方案。

    • 在下一页导航前分离行为
    • 从某个页面导航到上一个页面后的附加行为(如果使用 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
      行为。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-06
      • 1970-01-01
      • 1970-01-01
      • 2011-08-29
      相关资源
      最近更新 更多