从StoryBoard访问Grid.Columnspan

时间:2012-10-05 09:54:55

标签: wpf xaml

我有一个ListView占用Grid的单元格:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <ListView
        x:Name="itemListView"
        Grid.Column="0"
        Grid.ColumnSpan="2"
        />
</Grid>

我想在故事板中改变colspan:

<VisualState x:Name="Snapped">
    <Storyboard>
        <ObjectAnimationUsingKeyFrames
            Storyboard.TargetName="itemListView"
            Storyboard.TargetProperty="Grid.ColumnSpan">
            <DiscreteObjectKeyFrame KeyTime="0" Value="1" />
        </ObjectAnimationUsingKeyFrames>
    </Storyboard>
</VisualState>

但最终出现了运行时错误...

1 个答案:

答案 0 :(得分:7)

解决方案很简单,但并不明显(好吧,至少不适合我):

<ObjectAnimationUsingKeyFrames
    Storyboard.TargetName="itemListView"
    Storyboard.TargetProperty="(Grid.ColumnSpan)">
    <DiscreteObjectKeyFrame KeyTime="0" Value="1" />
</ObjectAnimationUsingKeyFrames>

它表明这种财产应该括在括号中。