Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7933687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:24:23+00:00 2026-06-03T21:24:23+00:00

I am essentially trying to create a Button with an image background and border

  • 0

I am essentially trying to create a Button with an image background and border that changes color based off if it is hovered, clicked or default state. I will several of these types of buttons, and I want to have a ControlTemplate defined that I can reuse and change the ImageSource. Here is what I have so far, but for some reason the TemplateBinding doesn’t seem to work. The buttons have no background image set.

Template:

    <ControlTemplate x:Name="SkillIconTemplate" TargetType="Button">
        <Border CornerRadius="10" BorderThickness="2" Margin="5">
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="CommonStates">
                    <VisualStateGroup.Transitions>
                        <VisualTransition To="MouseOver" GeneratedDuration="0:0:0.1"/>
                        <VisualTransition To="Pressed" GeneratedDuration="0:0:0.1"/>
                    </VisualStateGroup.Transitions>
                    <VisualState x:Name="Normal" />
                    <VisualState x:Name="MouseOver">
                        <Storyboard>
                            <ColorAnimation Storyboard.TargetName="BorderBrush" 
                                                    Storyboard.TargetProperty="Color" 
                                                    To="Yellow" />
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Pressed">
                        <Storyboard>
                            <ColorAnimation Storyboard.TargetName="BorderBrush" 
                                                    Storyboard.TargetProperty="Color"
                                                    To="Black"/>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <Border.BorderBrush>
                <SolidColorBrush x:Name="BorderBrush" Color="White"/>
            </Border.BorderBrush>
            <Border.Background>
                <ImageBrush ImageSource="{TemplateBinding local:SkillIcon.IconImageSource}"/>
            </Border.Background>
        </Border>
    </ControlTemplate>

Buttons:

    <Button x:Name="skillIcon0" Width="75" Height="75" ClickMode="Press" local:SkillIcon.IconImageSource="ms-appx:/data/images/icons/skill_icon_0.png" Template="{StaticResource SkillIconTemplate}"/>
    <Button x:Name="skillIcon1" Width="75" Height="75" ClickMode="Press" local:SkillIcon.IconImageSource="ms-appx:/data/images/icons/skill_icon_1.png" Template="{StaticResource SkillIconTemplate}"/>
    …

Property Code:

public abstract class SkillIcon : DependencyObject
{
    public static readonly DependencyProperty IconImageSourceProperty = DependencyProperty.RegisterAttached(
        "IconImageSource", 
        typeof(ImageSource), 
        typeof(SkillIcon),
        new PropertyMetadata(GetIconImage(0))
        );

    public static ImageSource GetIconImageSource(DependencyObject obj)
    {
        return (ImageSource)obj.GetValue(IconImageSourceProperty);
    }

    public static void SetIconImageSource(DependencyObject obj, ImageSource value)
    {
        obj.SetValue(IconImageSourceProperty, value);
    }

    /// <summary>
    /// Gets the image source for the button
    /// </summary>
    public static ImageSource GetIconImage(int index)
    {
        Uri source = new Uri(string.Format("ms-appx:/data/images/icons/skill_icon_{0}.png", index), UriKind.RelativeOrAbsolute);
        return new BitmapImage() { UriSource = source };
    }
}

Usage in code:

        SkillIcon.SetIconImageSource(skillIcon0, SkillIcon.GetIconImage(0));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T21:24:25+00:00Added an answer on June 3, 2026 at 9:24 pm

    I ended up binding the background of the Button to the background of the border:

        <ControlTemplate x:Name="SkillIconTemplate" TargetType="Button">
            <Border CornerRadius="10" BorderThickness="2" Margin="5" Background="{TemplateBinding Background}">
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualStateGroup.Transitions>
                            <VisualTransition To="MouseOver" GeneratedDuration="0:0:0.05"/>
                            <VisualTransition To="Pressed" GeneratedDuration="0:0:0.05"/>
                        </VisualStateGroup.Transitions>
                        <VisualState x:Name="Normal" />
                        <VisualState x:Name="MouseOver">
                            <Storyboard>
                                <ColorAnimation Storyboard.TargetName="BorderBrush" 
                                                        Storyboard.TargetProperty="Color" 
                                                        To="Yellow" />
                            </Storyboard>
                        </VisualState>
                        <VisualState x:Name="Pressed">
                            <Storyboard>
                                <ColorAnimation Storyboard.TargetName="BorderBrush" 
                                                        Storyboard.TargetProperty="Color"
                                                        To="Black"/>
                            </Storyboard>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
                <Border.BorderBrush>
                    <SolidColorBrush x:Name="BorderBrush" Color="White"/>
                </Border.BorderBrush>
            </Border>
        </ControlTemplate>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a Deep Zoom based multiscale image that essentially has
Alright so what I am trying to do is essentially create a program that,
I'm essentially trying to set it up so that when I click a button
I am trying to create a file that is essentially an e-mail with headers
Is this possible? Essentially I'm trying to create a div layout that looks like:
I am trying to create a javascript function within my html document that essentially
I am trying to create an SQL statement that will essentially calculate points due
I'm trying to essentially create a drop down menu tied to a field that
I'm trying to read a text document that is separated into essentially paragraphs of
I am trying create a small web application that allows a user to login

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.