WPF event event not working

I am new to programming (changing scope, leaving design) and quite interested in WPF. So I study and make codes. In this I am trying to create an "invisible" grid (gridNovoCliente, opacity = 0) to show on a button click event (opacity = 1) with all its elements. I want the grid / items to be invisible until the user clicks the button.

But it doesn't work. I already submitted it to Google 3 days before. I am getting the error "Set property" System.Windows.Media.Animation.Storyboard.Target is "throwing an exception". on the EventTrigger line.

There will be more buttons when I get this working, so I created a style. Thank you in advance! Here is the code.

<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>

      

+3


source to share


1 answer


    <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>

      



It's very simple, please try above xaml, it works for me. Thanks to

+3


source







All Articles