Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic Button Icon Windows app

Tags:

button

uwp

I'm trying to do a pause/play button windows 10 app.

So far I know 3 ways to set the button using

button.context = "some segoe code" - works fine when I initialize it with the button but on the code to change the context the button appears as a bunch of squares

Button symbolicon - works fine initializing but no idea how to alter the symbolicon value outside of button declaration

button uri - only thing I could find online about button changing, but I don't have the button libraries that come in windows phone...

what is your recommendations so on clickrelease the button changes to either the pause or the play

like image 792
John Avatar asked Feb 07 '16 07:02

John


1 Answers

I have used SymbolIcon to achieve the toggle play/pause.

XAML:

<Button Click="play_Click">
    <SymbolIcon x:Name="play" Symbol="Play"/>
</Button>

C# code behind:

private void play_Click(object sender, RoutedEventArgs e)
{
    if (play.Symbol.Equals(Symbol.Play))
    {
        play.Symbol = Symbol.Pause;
    }
    else if (play.Symbol.Equals(Symbol.Pause))
    {
        play.Symbol = Symbol.Play;
    }
}

Comment if you encounter any issues.

like image 190
Razor Avatar answered Oct 17 '22 09:10

Razor