3

我是编程新手(改变领域,离开设计)并且对 WPF 非常感兴趣。所以我正在学习并做一些代码。在这一个中,我正在尝试制作一个“不可见”网格(gridNovoCliente,opacity = 0)以显示在按钮单击事件(opacity = 1)及其所有元素。我希望网格/元素在用户单击按钮之前不可见。

但它不起作用。在决定在这里发布之前,我已经在谷歌上搜索了 3 天。我收到错误“设置属性 'System.Windows.Media.Animation.Storyboard.Target' 引发异常。” 在 EventTrigger 行。

一旦我得到这个工作,就会有更多的按钮,所以我创造了一种风格。提前致谢!这是代码。

<Grid>
        <Button Style="{StaticResource templateButton}" Name="novoCliente" Content="Novo&#xa;Cliente" Margin="20,41,0,598" TextBlock.TextAlignment="Center">
            <Button.Triggers>
                <EventTrigger RoutedEvent="Button.Click">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.Target="gridNovoCliente"
                                         Storyboard.TargetProperty="Opacity"
                                         From="0"
                                         To="1"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Button.Triggers>
        </Button>

    <Grid Height="705" HorizontalAlignment="Left" Margin="131,12,0,0" Name="gridNovoCliente" VerticalAlignment="Top" Width="859" Background="#FF6FAA6F" Opacity="0">
        <TextBox Height="70" HorizontalAlignment="Left" Margin="270,250,0,0" Name="textBox1" VerticalAlignment="Top" Width="358" />
    </Grid>
</Grid>
4

1 回答 1

4
    <Canvas>
        <Button  Name="novoCliente" Content="Novo&#xa;Cliente"  Margin="20,41,0,598" TextBlock.TextAlignment="Center">
        <Button.Triggers>
            <EventTrigger RoutedEvent="Button.Click" >
                <EventTrigger.Actions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="gridNovoCliente"
                                     Storyboard.TargetProperty="Opacity"
                                     From="0"
                                     To="1"/>
                        </Storyboard>
                    </BeginStoryboard>
               </EventTrigger.Actions> 

            </EventTrigger>
        </Button.Triggers>
    </Button>

    <Grid Height="705" HorizontalAlignment="Left" Margin="131,12,0,0" Name="gridNovoCliente" VerticalAlignment="Top" Width="859" Background="#FF6FAA6F" Opacity="0">
        <TextBox Height="70" HorizontalAlignment="Left" Margin="270,250,0,0" Name="textBox1" VerticalAlignment="Top" Width="358" />
    </Grid>
    </Canvas>

这很简单,请尝试上面的 xaml,它对我有用。谢谢

于 2013-01-22T13:53:15.653 回答