如何以编程方式将对象从右向左滑动到网格中
本文关键字:网格 编程 方式 对象 | 更新日期: 2023-09-27 17:55:10
使用 Silverlight
、XAML
和 C#
,如何以编程方式将Object/UserControl
从右向左滑动到我的视图中。
我遇到的问题是视频播放器从一开始就仍在屏幕上。我将起始网格点设置为网格列 9,但即使我只有 8 个网格列,它仍然显示。
我使用具有 8 x 8 相等网格布局的网格,如下所示;
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" ></ColumnDefinition>
<ColumnDefinition Width="*" ></ColumnDefinition>
<ColumnDefinition Width="*" ></ColumnDefinition>
<ColumnDefinition Width="*" ></ColumnDefinition>
<ColumnDefinition Width="*" ></ColumnDefinition>
<ColumnDefinition Width="*" ></ColumnDefinition>
<ColumnDefinition Width="*" ></ColumnDefinition>
<ColumnDefinition Width="*" ></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition x:Name="Row0" Height="*"></RowDefinition>
<RowDefinition x:Name="Row1" Height="*"></RowDefinition>
<RowDefinition x:Name="Row2" Height="*"></RowDefinition>
<RowDefinition x:Name="Row3" Height="*"></RowDefinition>
<RowDefinition x:Name="Row4" Height="*"></RowDefinition>
<RowDefinition x:Name="Row5" Height="*"></RowDefinition>
<RowDefinition x:Name="Row6" Height="*"></RowDefinition>
<RowDefinition x:Name="Row7" Height="*"></RowDefinition>
</Grid.RowDefinitions>
我已将视频播放器设置为从Grid.Col 9开始,但它仍然显示Col 8
播放器的当前 XAML 为
<Controls:VideoPlayer x:Name="videoPlayer"
Grid.Row="1"
Grid.RowSpan="6"
Grid.Column="9" <-- I wanted it off the grid but it still shows on col 8
Grid.ColumnSpan="3" Margin="15"
/>
我目前有
<Storyboard x:Name="slideInVideo">
<DoubleAnimation Storyboard.TargetName="videoPlayer"
Storyboard.TargetProperty="Grid.Column"
From="8" To="5" Duration="00:00:10"/>
</Storyboard>
你的方法有很多问题。
- 首先,AFAIK 当您没有 9 列时,您无法将元素设置为列
9
中的位置。 - 请注意,
Grid.Row
和Grid.Column
属性指向从零开始的索引。 - 最后但同样重要的;目标应
Storyboard.TargetProperty="(Grid.Column)"
注意括号,它是对附加属性进行动画处理所必需的。
可以使用表达式交互性和交互命名空间中可用的内置行为
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
xmlns:ee="http://schemas.microsoft.com/expression/2010/effects"
更多信息在这里...http://msdn.microsoft.com/en-us/library/ff724013(v=expression.40).aspx
诸如FluidMoveBehavior
和ExtendedVisualStateManager.TransitionEffect
之类的内容可以帮助您在加载时(或其他状态更改时)提供从屏幕一侧移入的元素的外观。