Macaret
Macaret

Reputation: 797

WP 8.1 BarButton Icon changing

I'm just starting to learn C# and WP platform and i find it really hard to do some easy things, like changing a button icon, etc.

I've got a Command Bar and a AppBarButton created in XAML.

<Page.BottomAppBar>
    <CommandBar MinHeight="60">
        <AppBarButton x:Name="Command_BarButton" Icon="AllApps" 
                      Label="Seletie"
                      Click="AppBar_Select"/>
    </CommandBar>
</Page.BottomAppBar>

I would like to change the AppBarButton icon programatically in C# to another prexistent icon, like the Trash icon. How can i do this ?

Command_BarButton.Label = "Delete";
Command_BarButton.Icon = ?

Upvotes: 0

Views: 753

Answers (3)

Macaret
Macaret

Reputation: 797

I knew it would be very easy to change the AppBarButton Icon at runtime.

This is how:

        Command_BarButton.Label = "Delete";
        Command_BarButton.Icon = new SymbolIcon(Symbol.Delete);

Thanks to this link

Upvotes: 2

user3346310
user3346310

Reputation:

to change Icon from code behind try this

ApplicationBar = new ApplicationBar();

ApplicationBarIconButton button1 = new ApplicationBarIconButton();
button1.IconUri = new Uri("/Images/play.png", UriKind.Relative);
button1.Text = "play";
ApplicationBar.Buttons.Add(button1);

source

Upvotes: 1

user3346310
user3346310

Reputation:

this shuold help

<AppBarButton Label="BitmapIcon" Click="AppBarButton_Click">
    <AppBarButton.Icon>
        <BitmapIcon UriSource="ms-appx:///Assets/globe.png"/>
    </AppBarButton.Icon>
</AppBarButton>

source

Upvotes: 0

Related Questions