1

我有一个名为 FluidPanel 的自定义类,它扩展了Panel并覆盖了方法 MeasureOverride 和 ArrangeOverride。目标是创建 Google Keep 外观。好的,它工作正常。(应用链接

但是,因为我正在扩展一个基本面板并将其用作 ItemsPanelTemplate,所以我缺少两件事:重新排序和一些转换,这根本无法开箱即用。见代码:

<GridView CanReorderItems="True" CanDrag="True" AllowDrop="True">
    <GridView.ItemContainerTransitions>
        <TransitionCollection>
            <EntranceThemeTransition FromVerticalOffset="200" IsStaggeringEnabled="True"/>
            <ReorderThemeTransition/>
        </TransitionCollection>
    </GridView.ItemContainerTransitions>

    <GridView.ItemsPanel>
        <ItemsPanelTemplate>
            <local:FluidPanel/><!--custom panel = reorder doesn't work-->
            <!--<StackPanel/>--><!--reorder and animations work normally (reorder to see)-->
        </ItemsPanelTemplate>
    </GridView.ItemsPanel>

    <Grid Width="50" Height="50" Background="Red"/>
    <Grid Width="50" Height="50" Background="Green"/>
    <Grid Width="50" Height="50" Background="Blue"/>
    <Grid Width="50" Height="50" Background="Orange"/>
    <Grid Width="50" Height="50" Background="Purple"/>
    <Grid Width="50" Height="50" Background="Pink"/>
</GridView>

所以,主要问题是:如何创建一个完全正常工作的自定义面板,包括动画?(就像向左/向右/的偏移量...)

第二个(不太重要的)问题是:EntranceThemeTransition 工作了吗?

4

1 回答 1

1

我部分找到了解决方案。
不幸的是,这并不像应该的那么容易。

对于自定义面板,似乎我们必须手动实现重新排序,监听拖放事件。

这是一篇关于它的文章:Extended GridView with Drag and Drop
,这是一个关于它的简化代码

通过手动更改视觉状态来添加重新排序动画:

private void OnDragOver(object sender, DragEventArgs e)
{
    var item = (e.OriginalSource as FrameworkElement).DataContext as Note;
    if (item == null) return;

    e.Data.Properties["targetItem"] = item;

    var itemContainer = (sender as ItemsControl).ContainerFromItem(item) as Control;
    if (itemContainer == null) return;

    VisualStateManager.GoToState(itemContainer, "BottomReorderHint", true);
}

但我仍然希望有任何更简单的方法来做到这一点,因为很多面板都实现了它(StackPanel,ItemsWrapGrid,...)。

仍然无法让 EntranceThemeTransition 在自定义面板上工作。
编辑: 使 EntranceThemeTransition 工作的解决方法

于 2015-07-25T08:32:37.863 回答