问题
I'm using UWP to build an XBOX ONE app. I have a GridView and I need to scale the width and height of the selected Item. Anyone has an example of how to perform that behavior?
回答1:
In UWP, how can I scale an item on GridView when item is selected?
Firstly, for how to scale an item you can use ScaleTransform class. You can scales an object in the two-dimensional x-y coordinate system. To meet your requirements here you can create a ScaleTranform
object for the ContentBorder
of the GridView
item's style template.
<Grid
x:Name="ContentBorder"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid.RenderTransform>
<ScaleTransform x:Name="contentborderscale"></ScaleTransform>
</Grid.RenderTransform>
Secondly, for how to change the visual state when item is selected, you need to change the PointerOverSelected
state or Selected
state based on the default GridViewItem styles and templates. You can add the following animations to the PointOverSelected
visual state to implement the scale.
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="contentborderscale" Storyboard.TargetProperty="ScaleY" >
<DiscreteObjectKeyFrame KeyTime="0" Value="1.5" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="contentborderscale" Storyboard.TargetProperty="ScaleX">
<DiscreteObjectKeyFrame KeyTime="0" Value="1.5" />
</ObjectAnimationUsingKeyFrames>
I wrote a completed demo about when the GridView
item selected, the height
and width
of the item will scale to 150%. You can download the demo here.
来源:https://stackoverflow.com/questions/39795718/in-uwp-how-can-i-scale-an-item-on-gridview-when-item-is-selected