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 7952975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:01:30+00:00 2026-06-04T03:01:30+00:00

I created a style for buttons inside a toolbar which is a combination of

  • 0

I created a style for buttons inside a toolbar which is a combination of a icon and text:

<Style TargetType="{x:Type Button}" x:Key="BtStyle_ToolBar">
    <Setter Property="Foreground" Value="White" />
    <Setter Property="FontWeight" Value="Bold" />
    <Setter Property="FontFamily" Value="Segoe UI" />
    <Setter Property="ContentTemplate">
        <Setter.Value>
            <DataTemplate DataType="{x:Type Button}">
                <StackPanel Orientation="Horizontal">
                    <Image Source="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button}, Path=Tag}" />
                    <TextBlock Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button}, Path=Content}" 
                               VerticalAlignment="Center" />
                </StackPanel>
            </DataTemplate>
        </Setter.Value>
    </Setter>
</Style>

Using it:

<Button Name="Bt_Export" Content="{x:Static p:Resources.Export}" Command="{Binding Path=CmdExport}"
                Padding="5" Style="{StaticResource BtStyle_ToolBar}" Tag="Resources/export_excel_16x16.png"/>

The problem is that at runtime an exception is thrown to the immediate window:

System.Windows.Data Error: 6 : 'ObjectSourceConverter' converter failed to convert value 'Resources/export_excel_16x16.png' (type 'String'); fallback value will be used, if available. BindingExpression:Path=Tag; DataItem='Button' (Name='Bt_Export'); target element is 'Image' (Name=''); target property is 'Source' (type 'ImageSource') IOException:'System.IO.IOException: Cannot locate resource 'themes/resources/export_excel_16x16.png'.

But at design time everything works fine…

How can I solve this issue?

EDIT (Workaround)

I removed the content property from the button declaration:

<Button Name="Bt_Export" Style="{StaticResource BtStyle_ToolBar}">
      <DockPanel>
           <Image Source="/Resources/export_excel_16x16.png"/>
           <TextBlock VerticalAlignment="center" Text="{x:Static p:Resources.Export}"></TextBlock>
       </DockPanel>
 </Button>
  • 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-04T03:01:32+00:00Added an answer on June 4, 2026 at 3:01 am
    <Button Name="Bt_Import" Command="{Binding Path=CmdImport}" Style="{StaticResource BtStyle_ToolBar}">
      <StackPanel>
        <TextBlock Text="{x:Static p:Resources.Import}"/>
        <Image Source="Resources/import_16x16.png"/>
      </StackPanel>
    </Button>
    

    Or just set it at the template level.

    <Style TargetType="{x:Type Button}" x:Key="BtStyle_ToolBar">
        <Setter Property="Foreground" Value="White" />
        <Setter Property="FontWeight" Value="Bold" />
        <Setter Property="FontFamily" Value="Segoe UI" />
        <Setter Property="ContentTemplate">
            <Setter.Value>
                <DataTemplate DataType="{x:Type Button}">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="Resources/import_16x16.png" />
                        <TextBlock Text="Awesome" 
                                   VerticalAlignment="Center" />
                    </StackPanel>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF button style below: <Style x:Key=myButtonStyle TargetType={x:Type Button}> <Setter Property=Template> <Setter.Value>
I have created a UserControl which has a button inside and also a style
I've created an user control element which has a button with an individual style.
I have created a default style for a Button including a custom ControlTemplate like
I created a report (using Report Builder 3.0) which has two page newsletter style
I tried to create a Style for DataGridTextColumn with the following code <Style TargetType={x:Type
I'm using primefaces' accordion panel. Inside the tabs i have forms which are created
I have created some tables with text fields inside, like in the contacts for
I have many images which are created dynamically and I am showing them inside
Is there a way to align text vertically (i.e. centered) inside a wpf button

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.