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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:13:31+00:00 2026-05-30T00:13:31+00:00

I used this MSDN tutorial to create an eye candy look for all the

  • 0

I used this MSDN tutorial to create an eye candy look for all the Button controls of my window, and that worked fine.

To make it even more reusable, I tried to put all in a UserControl: I created a ImageButton UC, then I encapsulated all that <Style> from <Window.Resources> to <UserControl.Resources>.

Then I changed my Button instances in XAML, from:

<Button Tag="Face.jpg" Content="Foo" />

To:

<uc:ImageButton Tag="Face.jpg" Content="Foo" />

And the style stopped being applied.

Here’s the UC code:

<UserControl x:Class="GDTI.UI.Main.View.UserControls.ImageButton"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">

<UserControl.Resources>
    <Style TargetType="Button">
        <Setter Property="MaxWidth" Value="250" />
        <Setter Property="Margin" Value="5" />
        <Setter Property="FontWeight" Value="Bold" />
        <Setter Property="Foreground" Value="White" />

        <Setter Property="Background" >
            <Setter.Value>
                <SolidColorBrush Color="Orange" Opacity="0.4" />
            </Setter.Value>
        </Setter>

        <Setter Property="ContentTemplate">
            <Setter.Value>
                <DataTemplate >
                    <StackPanel>
                        <Image Source="{Binding Tag,
                            RelativeSource={RelativeSource
                                              FindAncestor,
                                              AncestorType='Button'}}" />
                        <TextBlock Margin="10"
            HorizontalAlignment="Center"
            Text="{Binding Content,
                     RelativeSource={RelativeSource
                                       FindAncestor,
                                       AncestorType='Button'}}" />
                    </StackPanel>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</UserControl.Resources>

<Button/>

What am I missing?

Thank you!

  • 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-05-30T00:13:32+00:00Added an answer on May 30, 2026 at 12:13 am

    The bindings in the button-style target properties on the button, which no longer has the properties set. You need to forward those to the UserControl if you want to retain the style’s integrity:

    <!-- Inside UserControl declaration -->
    <Button Content="{Binding Caption, RelativeSource={RelativeSource AncestorType=UserControl}}"
            Tag="{Binding ImageSource, RelativeSource={RelativeSource AncestorType=UserControl}}"/>
    

    Where Caption and ImageSource should be new dependency properties defined on the UserControl (in code-behind).

    Note that you can never bind to Content in a UserControl (hence the Caption property), here the Button itself is the Content of the UserControl.

    Alternatively you could directly change the targeting in the style by changing the AncestorType to UserControl which bypasses the Button. Binding beyond the templated control is not exactly good practice but your are still inside the UserControl so it may be forgivable.

    Either way this is a bit hacky and it might be better to inherit from Button instead.

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

Sidebar

Related Questions

I used this code to print the current page: <form> <input type=button value=Print onClick=window.print();
this is in regards to the tutorial on msdn . This is whats used
According this MSDN article HttpApplication .EndRequest can be used to close or dispose of
I have used code like this: http://msdn.microsoft.com/en-us/library/dw70f090.aspx to access database before when working in
In the comments of this page: http://msdn.microsoft.com/en-us/library/12s31dhy%28v=VS.90%29.aspx ..it says that TransmitFile() cannot be used
This MSDN article states that getcwd() has been deprecated and that the ISO C++
I have used this page from MSDN to apply a custom style to my
I've been following this tutorial on msdn which loads a custom configSection. http://msdn.microsoft.com/en-us/library/system.configuration.configurationcollectionattribute.aspx I'm
Using code blocks or Dispose method hasn't used in this MSDN example about dialog
This MSDN article states that: An isolation level has connection-wide scope, and once set

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.