OnClick更改另一个元素的ZIndex

时间:2015-11-19 11:03:28

标签: c# .net wpf xaml z-index

<Button BorderThickness="0" Background="Transparent" Grid.Column="0" Padding="0" Grid.Row="0" Focusable="False" Width="Auto" >
    <Button.Content>
        <Grid HorizontalAlignment="Stretch">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <TextBlock Margin="0,0,6,0" Grid.Column="0" Text="Filter" Foreground="#FFC0B6D1" FontFamily="Segoe UI Semibold" FontSize="14" />
            <Image Grid.Column="1" Margin="0,4,0,0" VerticalAlignment="Center" Height="6" Width="12" Source="/SizeStream.WPF;component/Assets/filter-arrow-light.png"/>
        </Grid>
    </Button.Content>
    <Button.Triggers>
        <EventTrigger RoutedEvent="UIElement.PreviewMouseDown">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation BeginTime="0:0:0.00" Storyboard.TargetName="FiltersPanel" Storyboard.TargetProperty="Panel.ZIndex" From="2" To="3" Duration="0:0:00.2"/>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Button.Triggers>
</Button>

我有这个按钮。为此,我添加了EventTrigger,它必须更改名称为FiltersPanel的元素的ZIndex:

<Grid Margin="0,0,0,0" Panel.ZIndex="2" ClipToBounds="False" Grid.RowSpan="2" Grid.ColumnSpan="3" VerticalAlignment="Bottom" Name="FiltersPanel">...</Grid>

但是Onclick我得到了未处理的异常,我不知道为什么以及为了做什么。

1 个答案:

答案 0 :(得分:0)

您应该将动画更改为Int32Animation,而不要在此动画中使用附加属性Panel.ZIndex,只需重命名为ZIndex即可。所以代码就是这样。

<Int32Animation BeginTime="0:0:0.00" Storyboard.TargetName="FiltersPanel" Storyboard.TargetProperty="ZIndex" From="2" To="3" Duration="0:0:00.2"/>