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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:19:37+00:00 2026-06-03T00:19:37+00:00

I have created a template of a button, which contains an Image and a

  • 0

I have created a template of a button, which contains an Image and a TextBlock. Since I would like to change the appearance of both, I think they need to be in the Template. But, of course, not every instance of this template should present the same text and image.

Until now, i found a promising property called “Use a custom path expression” at the “Text” / “Source”-value filed of the TextBlock / Image at:

Data Binding... > Element Property > Use a custom path expression

I would now like to set this value at the instances of the button. I already tried to manually insert a myText="Lorem Ipsum" in the XAML of the Button, but that does not seem to work.

Thank you in advance for your help!

Update: This is, how the XAML looks like:

<TextBlock [...] Text="{Binding myText, ElementName={x:Null}, FallbackValue=Lorem}"/>

How do I access this or modify this, so it can be accessed?

Update 2: There already exist bindings for the TextBlock and the Image. At the moment, the XAML of the Button looks like that:

<s:SurfaceButton Command="{Binding SearchCustomCommand}" Style="{DynamicResource BasicButton}">
    <StackPanel Orientation="Vertical" Height="60" Width="48" IsHitTestVisible="False">
        <Image Source="{StaticResource ImageSourceToolboxSearchIcon}" 
            [...]
            Stretch="Uniform" />
        <TextBlock Text="{lex:LocText ToolboxButtonSearchesCustom}" 
            FontFamily="{DynamicResource button.font}" 
            [...]
            FontSize="{DynamicResource button.size}" 
            Foreground="{DynamicResource button.color.default}"/>
    </StackPanel>
</s:SurfaceButton>

I would now like to extract the Image and Textbox to the template (which also already exists), so I could refrence the Button in a way like this (whith all the Information about sizes and colors etc in the template and only the reference to the resource in the actual instance of the button – to be able to change the image/text for echt button seperately):

<s:SurfaceButton
    Command="{Binding SearchPopularCommand}"
    Style="{DynamicResource ToolboxButtonBig}"
    ImageSource="{StaticResource ImageSourceToolboxSearchIcon}"
    TextBlockSource="{lex:LocText ToolboxButtonSearchesCustom}"/>

I already copied the whole XAML for the StackPanel and the included TextBlock and Image to the Template. Now those are shown on every Button (which is fine), but i can’t change the contents of them.

I’m sorry if the description is quite poor – I’m rather new to WPF…

Update 3: After some further research, I found questions similar to mine – which obviously describe the problem better than I could:

  • Button template with image and text in wpf
  • Creating an image+text button with a control template?
  • 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-03T00:19:38+00:00Added an answer on June 3, 2026 at 12:19 am

    it is not necessary to edit button’s template to insert image and text, you can set Button.Content property like this:

    <Button>
            <Button.Content>
                <StackPanel Orientation="Horizontal">
                    <Image Source="../Images/image.png"/>
                    <TextBlock Text="Lorem Ipsum"/>
                </StackPanel>
            </Button.Content>
        </Button>
    

    and it will work well. example above can be simplified but I inserted it like this for better understanding what is going on.

    EDIT:
    here are examples how it can be done in two different ways:
    overwriting template:

    <Button Content="Lorem Ipsum">
            <Button.Template>
                <ControlTemplate TargetType="Button">
                    <StackPanel Orientation="Horizontal">
                        <Image x:Name="ButtonImage" Source="../Images/mouseNotOverImage.png"/>
                        <ContentPresenter Margin="2"
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"
                            RecognizesAccessKey="True" />
                    </StackPanel>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="ButtonImage" Property="Source" Value="../Images/mouseOverImage.png"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Button.Template>
        </Button>
    

    complete button template definition you can find here
    modifying style:

    <Button>
            <Button.Style>
                <Style TargetType="Button">
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Content">
                                <Setter.Value>
                                    <StackPanel Orientation="Horizontal">
                                        <Image Source="../Images/mouseOverImage.png"/>
                                        <TextBlock Text="Lorem Ipsum"/>
                                    </StackPanel>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="False">
                            <Setter Property="Content">
                                <Setter.Value>
                                    <StackPanel Orientation="Horizontal">
                                        <Image Source="../Images/mouseNotOverImage.png"/>
                                        <TextBlock Text="Lorem Ipsum"/>
                                    </StackPanel>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </Button.Style>
        </Button>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have template in which a button is created with a link using css,
I have an interesting problem. I've created a WPF UserControl which contains a button
If I have a template as follows, which is used to create a button:
I have created my own ControlTemplate for Button, like this: <Style x:Key=LightButtonStyle TargetType={x:Type ButtonBase}>
I would like to create a UIButton which uses a stretchable image as Background
I am new to Vaadin. I have created template for my web application in
I have created an editor template for representing selecting from a dynamic dropdown list
I have created a UItableView using the default Xcode template and configure it to
I have created a custom style and template for MenuItem and ContextMenu, and for
I have started a project from an XCode template I have created. When I

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.