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

  • SEARCH
  • Home
  • 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 8913933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:35:17+00:00 2026-06-15T04:35:17+00:00

When I am working on a button template I just encountered a binding StringFormat

  • 0

When I am working on a button template I just encountered a binding StringFormat issue. Here it is.

— I setup a button with a given ToolTip as a string. I like to use it to specify the image name within binding. Then I apply it to a button style called ImageButton.

<Button ToolTip="Minimize" Height="34" Style="{StaticResource ImageButton}"  Margin="220,36,125,371" />;

— This is the code in style. I like to use the image name from the binding and come up with a full image path. It is supposed to be working like this, <Image x:Name="ButtonImage" Source="Images/Minimize-Normal.png" />. Yes, I do have such a image in place and it works great if I just put the xml code without binding.

<Image x:Name="ButtonImage" Source="{Binding ToolTip, RelativeSource={RelativeSource TemplatedParent}, StringFormat={}Images/{0}-Normal.png}" />

But the binding did not work as I expected. The image cannot be shown correctly. If I put the Image full name in ToolTip then it worked correct. It looks like the StringFormat had been ignored.

Any help will be appreciated. Thanks in advance.


Thanks for dbaseman’s response. I know I can achieve it by using Converter. But as I think StringFormat is easier to apply, that’s why I tried this.

I also found a reply here, it says – StringFormat is used when binding to a string property, while the Text property in your control is of type object, hence StringFormat is ignored.


It should be by design. Below code works. Because the Text property is string type.

<TextBlock Text="{Binding ToolTip, RelativeSource={RelativeSource Self}, StringFormat={}Images/{0}-Normal.png}" ToolTip="Minimize" />
  • 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-15T04:35:18+00:00Added an answer on June 15, 2026 at 4:35 am

    That’s interesting — I’m not sure if it’s a bug, or by design. You can work around this problem, though, by using a Converter instead of StringFormat.

    public class ImageNameConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return string.Format("Images/{0}-Normal.png", value);
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    

    And then of course:

    <local:ImageNameConverter x:Key="ImageNameConverter" />
    

    And:

    <Image x:Name="ButtonImage" 
        Source="{Binding ToolTip, 
                    RelativeSource={RelativeSource TemplatedParent}, 
                    Converter="{StaticResource ImageNameConverter}}" />
    

    Edit I think it’s by design. From the docs for BindingBase.StringFormat:

    Gets or sets a string that specifies how to format the binding if it displays the bound value as a string.

    So (apparently) the string-format conversion won’t happen unless the binding source is to actually be rendered as a text string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi all, I am working on creating a button template to use in my
I have a MVP application implemented. Back button is working fine. I'd like to
I'm working on an app where I'd like to use cocos2d in the app's
I was working on my button template with this example: http://msdn.microsoft.com/en-us/library/ms753328.aspx I found the
im using the WPFToolkit's DataGrid and im trying to get an edit button working,
I need a for a project i'm working on a button similar to the
I am working on a project where the button needs to have a certain
I'm working with an AJAX button and label controls. When the user clicks the
I have this button which is not working correctly for hold button for a
I have working with a project and i added a share button to product

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.