locked
Change AutomationProperties.AutomationId of a button control programmatically

    Question

  • We put some buttons in the top AppBar, all buttons follow the same pattern like

    <Button x:Uid="GraphLayerAnimate" x:Name="GraphLayerAnimate" Grid.Row="2" Grid.Column="2"
    Style="{StaticResource AppBarButtonStyle}" 
    Tag="Animate" AutomationProperties.AutomationId="PlayAppBarButton" Content="&#xE102;"  
    ToolTipService.ToolTip="Start Animation" Click="OnGraphicsLayerAnimationPressed"/>
    
    When user clicks this button, we need to start the animation and change the button image to "PauseAppBarButton" with content "&#xE103". When user clicks the button the second time, we need to change the button image to that in the beginning. How can I do this?
    Wednesday, January 23, 2013 3:40 PM

Answers

  • Hi

    Do you want to change the content when click the button? If so, you can follow this codes.

           <Button FontFamily="Segoe UI Symbol"  Name="Mybutton" Content="&#xE0BA;" HorizontalAlignment="Left" Margin="536,294,0,0" VerticalAlignment="Top" Click="Mybutton_Click_1" Height="48" Width="102"/>
    
    void App1::MainPage::Mybutton_Click_1(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
    {
    	if(Changed)
    	{
    		this->Mybutton->Content=L"\ue0BA";
    		Changed=false;
    	}else{
    		this->Mybutton->Content=L"\ue0AC";
    		Changed=true;
    	};
    }
    


    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Leonard Saturday, January 26, 2013 12:35 AM
    Friday, January 25, 2013 7:41 AM

All replies

  • This thread on the XAML C# Forum might provide some inspiration:
    Issue With Visual States [Wednesday, September 05, 2012 6:41 PM] uses a ToggleButton [i.e. a Button with 2 states] based solution. It switches the state based on the IsChecked property binding capability.

    Wednesday, January 23, 2013 3:58 PM
  • Thank you very much for your quick response. As I'm new to XAML and could not see what you mean, could you please implement your method based on my XAML code posted in the original thread?
    Wednesday, January 23, 2013 10:24 PM
  • If no one can answer my question, could the moderator move this post to the right forum? thanks.
    Friday, January 25, 2013 6:34 AM
  • Hi

    Do you want to change the content when click the button? If so, you can follow this codes.

           <Button FontFamily="Segoe UI Symbol"  Name="Mybutton" Content="&#xE0BA;" HorizontalAlignment="Left" Margin="536,294,0,0" VerticalAlignment="Top" Click="Mybutton_Click_1" Height="48" Width="102"/>
    
    void App1::MainPage::Mybutton_Click_1(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
    {
    	if(Changed)
    	{
    		this->Mybutton->Content=L"\ue0BA";
    		Changed=false;
    	}else{
    		this->Mybutton->Content=L"\ue0AC";
    		Changed=true;
    	};
    }
    


    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Leonard Saturday, January 26, 2013 12:35 AM
    Friday, January 25, 2013 7:41 AM
  • It works. Thank you.
    Saturday, January 26, 2013 12:35 AM