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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:12:18+00:00 2026-06-12T18:12:18+00:00

I have the following style inside a resource dictionay <Setter Property=Template> <Setter.Value> <ControlTemplate TargetType=Button>

  • 0

I have the following style inside a resource dictionay

<Setter Property="Template">
    <Setter.Value>
        <ControlTemplate TargetType="Button">

            <Grid>
                <Rectangle Fill="#262626" Name="Normal"/>
                <Rectangle Fill="#3f3f41" Name="Hover" Visibility="Hidden"/>
                <Rectangle Fill="#007acc" Name="Pressed" Visibility="Hidden"/>

                <Image Name="Icon"/>
                <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Grid>

            <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter TargetName="Hover" Property="Visibility" Value="Visible"/>
                    <Setter TargetName="Pressed" Property="Visibility" Value="Hidden"/>
                </Trigger>
                <Trigger Property="IsPressed" Value="True">
                    <Setter TargetName="Pressed" Property="Visibility" Value="Visible"/>
                    <Setter TargetName="Hover" Property="Visibility" Value="Hidden"/>
                </Trigger>
            </ControlTemplate.Triggers>

        </ControlTemplate>
    </Setter.Value>
</Setter>

And I need to change the “Source” of the image with name “Icon” from my button (inside my MainWindow.xaml)

        <Button Style="{StaticResource ToolbarButton}">
            <Setter TargetName="Icon" Property="Source" Value=".png"/>
        </Button>

But it gives me the error “Source is not recognized or is not accesible”

How can I change the “Source” attribute of my image with name “Icon” from a 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-12T18:12:20+00:00Added an answer on June 12, 2026 at 6:12 pm

    WPF controls actually runs in behaviors. Buttons are not intended to have an Image. Although as button is a Contentcontrol you can put anything inside the content of the Button.

    <Button>
    <image ... />
    </Button
    

    In the style above you can use :

            <Grid>
                <Rectangle Fill="#262626" Name="Normal"/>
                <Rectangle Fill="#3f3f41" Name="Hover" Visibility="Hidden"/>
                <Rectangle Fill="#007acc" Name="Pressed" Visibility="Hidden"/>
    
                <Image Name="Icon" Source="{TemplateBinding Tag}" />
                <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Grid>
    
            <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter TargetName="Hover" Property="Visibility" Value="Visible"/>
                    <Setter TargetName="Pressed" Property="Visibility" Value="Hidden"/>
                </Trigger>
                <Trigger Property="IsPressed" Value="True">
                    <Setter TargetName="Pressed" Property="Visibility" Value="Visible"/>
                    <Setter TargetName="Hover" Property="Visibility" Value="Hidden"/>
                </Trigger>
            </ControlTemplate.Triggers>
    
        </ControlTemplate>
    </Setter.Value>
    

    Now you can specify the Source in the Tag property of the Button

    But this is not a right way to do. You should use TemplateBinding to the properties that supports the control behaviour. Like TemplateBinding to Background as button supports it, while button doesnt support an Image.

    Let me know if you need anything else.

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

Sidebar

Related Questions

I have following user control: <UserControl.Resources> <Style TargetType=HeaderedItemsControl> <Setter Property=Template> <Setter.Value> <ControlTemplate TargetType=HeaderedItemsControl> <Grid>
I have the following scenario: <UserControl.Resources> <Style x:Key=NormalFontStyle> <Setter Property=Control.FontFamily Value={Binding MyFont}></Setter> </Style> <Style
I have the following XAML/Control Template for a ListViewItem: <Window.Resources> <ControlTemplate x:Key=ItemTemplate TargetType=ListViewItem> <Border
Assume I have the following style table, col1 col2 and col3 have same value
I have the following piece of code that generate a jquerymobile-style button <a href=#
I have the following XAML inside a 4 Row by 2 column grid. The
I have a table inside of a div with the following style: #data {
I have the following style for my footers in my css file: #footer {
I have the following style defined which is being applied (as text changes to
I have a span with the following style: margin: 5px 0; padding: 2px; cursor:

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.