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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:28:59+00:00 2026-06-01T13:28:59+00:00

I have a style for button. That style contains the ControlTemplate for Button. The

  • 0

I have a style for button. That style contains the ControlTemplate for Button. The ControlTemplate contains an Image with name “ImgButton”.

I want to make this style as base style for other Buttons and want to override the “Source” property of Image control for different buttons.

Any ideas?

  • 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-01T13:29:00+00:00Added an answer on June 1, 2026 at 1:29 pm

    You may create attached behavior that will offer a property to assign Source. You should bind your image to this property in a template using TemplatedParent as RelativeSource. In derived styles you can simply use Setter(s) to specify a different Source.

    Attached behavoir:

    public static class ImageSourceBehavior
    {
        public static readonly DependencyProperty SourceProperty = DependencyProperty.RegisterAttached(
            "Source", typeof(ImageSource), typeof(ImageSourceBehavior),
            new FrameworkPropertyMetadata(null));
    
        public static ImageSource GetSource(DependencyObject dependencyObject)
        {
            return (ImageSource)dependencyObject.GetValue(SourceProperty);
        }
    
        public static void SetSource(DependencyObject dependencyObject, ImageSource value)
        {
            dependencyObject.SetValue(SourceProperty, value);
        }
    }
    

    Styles:

    <Style x:Key="Style1"
            TargetType="Button">
        <Setter Property="local:ImageSourceBehavior.Source"
                Value="..."/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Image Source="{Binding Path=(local:ImageSourceBehavior.Source),RelativeSource={RelativeSource TemplatedParent}}"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <Style x:Key="Style2"
            BasedOn="{StaticResource Style1}"
            TargetType="Button">
        <Setter Property="local:ImageSourceBehavior.Source"
                Value="..."/>
    </Style>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have style sheet with a class name changebackgroundcolor i want make change in
I have a WPF grid that contains, among other things, a button. The button
I have a Button Style: <Style x:Key=ButtonStyle1 TargetType={x:Type Button}> <Setter Property=Template> <Setter.Value> <ControlTemplate TargetType={x:Type
I have created a default style for a Button including a custom ControlTemplate like
Basically I have a webcontrol that contains a gridview with an export button. When
I have a div that contains within itself logout button and username. If the
I have a custom templated control(toolbar) that contains a custom usercontrol(button) The button uses
I have a border that contains a TabControl in a HeaderedContentControl: <Border Grid.Column=1 Style={StaticResource
I have a style rule I want to apply to a tag when it
does Delphi 2010 have C# Style XML comments that show up when hovering over

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.