Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to convert a string to Windows.UI.Xaml.Controls.IconElement

I couldn't find how to use the SymbolIcon.Symbol to change an appbar icon...

This is to understand what I need to do:

if (SecondaryTile.Exists(ItemId))
{
    PinToStart.Icon = "UnPin"; //instead of "Pin"
}
like image 601
the_nuts Avatar asked Sep 16 '25 04:09

the_nuts


1 Answers

Tha AppBarButton's Icon is IconElement type so you cannot just put there a string. If you want to use a Symbol you can do it like this:

PinToStart.Icon = new SymbolIcon(Symbol.UnPin); //instead of "Pin"

But I've encountered some problems while exchanging only Icons. I'm not sure if they are still there after some updates. If they are, I suggest to exchange the whole `AppBarButton

private AppBarButton pin
{
    get
    {
       AppBarButton temp = new AppBarButton() { Icon = new SymbolIcon(Symbol.Pin) };
       temp.Label = "Pin";
       temp.Click += Pin_Click;
       return temp;
    }
}

private AppBarButton unPin
{
    get
    {
       AppBarButton temp = new AppBarButton() { Icon = new SymbolIcon(Symbol.UnPin) };
       temp.Label = "UnPin";
       temp.Click += UnPin_Click;
       return temp;
    }
}

Then in the code exchange like this:

(BottomAppBar as CommandBar).PrimaryCommands[0] = pin; // assign the whole button when Pin/unPin
like image 132
Romasz Avatar answered Sep 19 '25 12:09

Romasz