add tag
Anonymous 1317
I'm writing a small test tool which is an UWP app.  I have a custom icon called MyIcon.png in Assets/Images.

There is a button defined as below:

           <Button Command="{x:Bind ViewModel.DoSomethingBtnClick}"
                    Grid.Column="3" Grid.Row="0"
                    Margin="30,20,0,0" VerticalAlignment="Top" Width="95" Height="70">
                    <!--I want to add the icon here -->
                    <TextBlock Text="Do Something" TextWrapping="WrapWholeWords" HorizontalTextAlignment="Center"/>

How do I add the icon to the button?
Top Answer
Joan Magnet
If you don't want to use a glyph, you can use an image in the usual way:


Have a look at this answer on SO:

In fact I found one example in one of my apps:

<Button Style="{StaticResource BtnLeftMenuStyle}"
        ToolTip="Button tooltip"
        Command="{Binding UpdateCurrentViewCommand}"
        <StackPanel Orientation="Vertical">
                    <Image Source="{StaticResource Planols}"
                    Style="{StaticResource ImgBtnMenuLateral}"/>
                    <TextBlock Text="Planol"
                               Style="{StaticResource TextBtnMenuLateral}"/>

And this is my resource dictionary:

<ResourceDictionary xmlns=""

    <!-- Lateral menu -->
    <BitmapImage x:Key="Home" UriSource="/Sysmac.Maquina;component/Assets/HomeBlue.png"/>
    <BitmapImage x:Key="Produccio" UriSource="/Sysmac.Maquina;component/Assets/ProductionBlue.png"/>
    <BitmapImage x:Key="Settings" UriSource="/Sysmac.Maquina;component/Assets/SettingsBlue.png"/>
    <BitmapImage x:Key="Sortir" UriSource="/Sysmac.Maquina;component/Assets/PowerOffBlue.png"/>
    <BitmapImage x:Key="Planols" UriSource="/Sysmac.Maquina;component/Assets/DesignBlue.png"/>
    <BitmapImage x:Key="Crono" UriSource="/Sysmac.Maquina;component/Assets/CronoBlue.png"/>
    <BitmapImage x:Key="Minimize" UriSource="/Sysmac.Maquina;component/Assets/MinimizeBlue.png"/>
    <BitmapImage x:Key="Operari" UriSource="/Sysmac.Maquina;component/Assets/CustomerBlue.png"/>
    <BitmapImage x:Key="Basura" UriSource="/Sysmac.Maquina;component/Assets/TrashBlue.png"/>

    <!-- Logo -->
    <BitmapImage x:Key="Logo" UriSource="/Sysmac.Maquina;component/Assets/AIS_Logo.png"/>


Just remember to set:

Build action = Resource

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.