.NET Framework Bookmark and Share   
 index > Windows Presentation Foundation (WPF) > button is not displayed
 

button is not displayed

<Window.Resources>
   <Storyboard x:Key="bn5Click">
   <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="button5" Storyboard.TargetProperty="(UIElement.Visibility)">
                <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}"/>
                <DiscreteObjectKeyFrame KeyTime="00:00:01" Value="{x:Static Visibility.Hidden}"/>
    </ObjectAnimationUsingKeyFrames>
    </Storyboard>  
</Window.Resources>
<!----------------------------------------------------------->
<Window.Triggers>
  <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="button5">
            <BeginStoryboard Storyboard="{StaticResource bn5Click}"/>
        </EventTrigger>
</Window.Triggers>
<!--BUTTON -->
<Button x:Name="button5" RenderTransformOrigin="0.5,0.5">
       <Button.RenderTransform>
               <TransformGroup>
                        <ScaleTransform ScaleX="1" ScaleY="1"/>
                        <SkewTransform AngleX="0" AngleY="0"/>
                        <RotateTransform Angle="0"/>
                        <TranslateTransform X="0" Y="0"/>
               </TransformGroup>
       </Button.RenderTransform>
</Button>
private void button6_Click(object sender, RoutedEventArgs e)
{
      button5.Visibility = Visibility.Visible;
}
When clicking on button6, it does not appear button5 .... Prompt please, what is the problem?
GGLeBaTi
I believe the problem is that the Storyboard is "holding" the value at Visibility.Hidden due to your timeline. This is due to the FillBehavior .

It's often somewhat problematic mixing properties changing via storyboards with properties changing in CodeBehind. In this case, I'd work around this issue by just adding a storyboard to make the button visible again, and triggering it on button6's click. This is nicer in many ways, since it's 100% xaml, and no code behind. (Plus, it works)

Here's some working code you can try:


    <Window.Resources>
        <Storyboard  x:Key="bn5Click">
            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="button5" Storyboard.TargetProperty="(UIElement.Visibility)" Duration="00:00:01">
                <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}"/>
                <DiscreteObjectKeyFrame KeyTime="00:00:01" Value="{x:Static Visibility.Hidden}"/>
            </ObjectAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard  x:Key="bn6Click">
            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="button5" Storyboard.TargetProperty="(UIElement.Visibility)" >
                <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}"/>
            </ObjectAnimationUsingKeyFrames>
        </Storyboard>
    </Window.Resources>
    <Window.Triggers>
        <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="button5">
            <BeginStoryboard Storyboard="{StaticResource bn5Click}"/>
        </EventTrigger>
        <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="button6">
            <BeginStoryboard Storyboard="{StaticResource bn6Click}"/>
        </EventTrigger>
    </Window.Triggers>
    <Grid>
        <Button x:Name="button5" />
        <Button Name="button6" HorizontalAlignment="Right" Width="69" Height="60" VerticalAlignment="Bottom" />
    </Grid>


Reed Copsey, Jr. - http://reedcopsey.com
  • Marked As Answer byGGLeBaTi Tuesday, September 22, 2009 5:26 PM
  •  
Reed Copsey, Jr.
You're not showing the XAML where you define button6 - make sure that button6 is actually setup to use the button6_Click event. If you do that, it should work propertly.
Reed Copsey, Jr. - http://reedcopsey.com
Reed Copsey, Jr.
You're not showing the XAML where you define button6 - make sure that button6 is actually setup to use the button6_Click event. If you do that, it should work propertly.
Reed Copsey, Jr. - http://reedcopsey.com
<Button Name="button6" HorizontalAlignment="Right" Width="69" Height="60" VerticalAlignment="Bottom" Click="button6_Click">
 </Button>
help me please )
GGLeBaTi
I believe the problem is that the Storyboard is "holding" the value at Visibility.Hidden due to your timeline. This is due to the FillBehavior .

It's often somewhat problematic mixing properties changing via storyboards with properties changing in CodeBehind. In this case, I'd work around this issue by just adding a storyboard to make the button visible again, and triggering it on button6's click. This is nicer in many ways, since it's 100% xaml, and no code behind. (Plus, it works)

Here's some working code you can try:


    <Window.Resources>
        <Storyboard  x:Key="bn5Click">
            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="button5" Storyboard.TargetProperty="(UIElement.Visibility)" Duration="00:00:01">
                <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}"/>
                <DiscreteObjectKeyFrame KeyTime="00:00:01" Value="{x:Static Visibility.Hidden}"/>
            </ObjectAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard  x:Key="bn6Click">
            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="button5" Storyboard.TargetProperty="(UIElement.Visibility)" >
                <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}"/>
            </ObjectAnimationUsingKeyFrames>
        </Storyboard>
    </Window.Resources>
    <Window.Triggers>
        <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="button5">
            <BeginStoryboard Storyboard="{StaticResource bn5Click}"/>
        </EventTrigger>
        <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="button6">
            <BeginStoryboard Storyboard="{StaticResource bn6Click}"/>
        </EventTrigger>
    </Window.Triggers>
    <Grid>
        <Button x:Name="button5" />
        <Button Name="button6" HorizontalAlignment="Right" Width="69" Height="60" VerticalAlignment="Bottom" />
    </Grid>


Reed Copsey, Jr. - http://reedcopsey.com
  • Marked As Answer byGGLeBaTi Tuesday, September 22, 2009 5:26 PM
  •  
Reed Copsey, Jr.
Thank you!)
GGLeBaTi

You can use google to search for other answers

Custom Search

More Threads

• XML saving gives cannot add simplecontent column
• Repeate Count in the MediaElement tag
• ObjectDataProvider and binding to MethodParameters
• Problems with Windows themes other than Windows XP standard theme.
• RichTextBox combining Inlines.
• Logically grouping controls to have many instances of the same control with the same name.
• Systray icon with WPF
• Problem with two way data binding to user control
• Does it good choice to build a website like Ebay with Xbap ?
• Binding error when binding to datatable with column that has special characters