繁体   English   中英

WP7:LayoutTransform一个ListBoxItem

[英]WP7: LayoutTransform a ListBoxItem

这是我的XAML:

<ListBox x:Name="MyListBox" FontSize="40"
            SelectionChanged="MyListBox_SelectionChanged">
</ListBox>            

在下面的代码中(以下),我尝试为删除操作设置动画。 选择该项目后,我将其删除。 我使用ScaleTransform在视觉上对其进行动画处理。 在WPF中,我将使用LayoutTransform,但是由于我在WP / SL中只有RenderTransform,因此我正在使用RenderTransform-结果是周围的布局对大小的变化没有响应。 记录仍然正确删除,但是视觉效果减弱。

有没有办法在WP中做到这一点? 有没有一种方法可以调整ListBoxItem的大小,以便周围的内容能够响应?

ObservableCollection<string> m_Data;

public MainPage()
{
    InitializeComponent();
    m_Data = new ObservableCollection<string>   
        { "One", "Two", "Three", "Four" };
    MyListBox.ItemsSource = m_Data;
}

private void MyListBox_SelectionChanged(object sender,
    SelectionChangedEventArgs e)
{
    // fetch ListBoxItem
    if (e.AddedItems.Count == 0)
        return;
    var _Data = e.AddedItems[0] as string;
    var _Item = MyListBox.ItemContainerGenerator
        .ContainerFromItem(_Data) as ListBoxItem;

    // setup to resize using scale transform
    var _Scale = new ScaleTransform
    {
        CenterX = _Item.RenderSize.Width / 2,
        CenterY = _Item.RenderSize.Height / 2,
        ScaleX = .99,
        ScaleY = .99
    };
    _Item.RenderTransform = _Scale;

    // setup storyboard
    var _Story = new Storyboard();
    _Story.Completed += (s, e1) =>
    {
        // remove data from collection
        m_Data.Remove(_Data);
    };

    // animate scale X
    var _AnimationX = new DoubleAnimation
    {
        To = .01,
        Duration = TimeSpan.FromSeconds(2),
    };
    _Story.Children.Add(_AnimationX);
    Storyboard.SetTarget(_AnimationX, _Scale);
    Storyboard.SetTargetProperty(_AnimationX,
        new PropertyPath(ScaleTransform.ScaleXProperty));

    // animate scale Y
    var _AnimationY = new DoubleAnimation
    {
        To = .01,
        Duration = TimeSpan.FromSeconds(2),
    };
    _Story.Children.Add(_AnimationY);
    Storyboard.SetTarget(_AnimationY, _Scale);
    Storyboard.SetTargetProperty(_AnimationY,
        new PropertyPath(ScaleTransform.ScaleYProperty));

    _Story.Begin();
}

您也可以在Windows Phone上使用LayoutTransform,所以我只用它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM