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

The Archive Base Latest Questions

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

I’m a professional Windows application developer in VB.NET and C# with Windows Forms, and

  • 0

I’m a professional Windows application developer in VB.NET and C# with Windows Forms, and now very excited to step into WPF development. Here my first issue I couldn’t solve by searching:

I wrote the following template to completely change the appearance of my buttons:

    <ControlTemplate TargetType="{x:Type Button}" x:Key="ImageButtonTemplate">
        <Grid>
            <Image Name="img" Source="/PSPlayer;component/Images/Buttons/ButtonNormal_normal.png"/>
            <ContentPresenter Stylus.IsTapFeedbackEnabled="False" Stylus.IsTouchFeedbackEnabled="False" Stylus.IsPressAndHoldEnabled="False" Stylus.IsFlicksEnabled="False" Width="98" Height="61"/>
        </Grid>

        <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter TargetName="img" Property="Source" Value="/PSPlayer;component/Images/Buttons/ButtonNormal_MouseOver.png"/>
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
                <Setter TargetName="img" Property="Source" Value="/PSPlayer;component/Images/Buttons/ButtonNormal_MouseDown.png"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

and here a button definition:

        <Button Content="SomeText" Height="61" Margin="0,0,0,7" Name="button7" Width="98" Click="button7_Click" Template="{StaticResource ImageButtonTemplate}"/>

The problem is, that the Text “SomeText” appears in the top left of the button and I cannot change that location. The buttons’ properties HorizontalContentAlignment and VerticalContentAlignment don’t show an effect (I’m wondering why).

Additionally I would like to position the text to a certain location sometimes, like x=70 when the backgound image has a symbol in it that locates on the left side until x=60.

I made a walkaround with a label embedded inside the button that I could position but think there must be a cleaner solution.

Hope I made myself clear. WPF rulez by the way – as well as this site, most of my problems I solved with postings from here (coming from google) 🙂

Thanks in advance,

Julian

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

    A few things are happening here. Your first problem is that you set an absolute size for your ContentPresenter (in general, in WPF, you avoid absolute sizes and absolute positions for controls, but it’s a hard habit to break when you are coming from WinForms). If you remove that it will can be aligned properly by setting the VerticalAlignment and HorizontalAlignment of the ContentPresenter itself. The reason why setting the VerticalAlignment and the HorizontalAlignment on the button itself doesn’t work is because you are not using those properties anywhere in your template. Ideally, you’d do something like this:

    <ContentPresenter VerticalAlignment="{TemplateBinding VerticalAlignment}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}"/>
    

    And now you can set the alignment on the button that uses this template. Of course, if you always want this template to be centered, you can just hardcode it rather than using the TemplateBinding.

    In general, the thing to remember when replacing templates is that any property of the control that you are not explicitly binding in your template is going to be ignored by WPF when it renders your control. If you don’t tell it what to do with those properties it isn’t going to guess. A rare exception is the content property in your example which you can get away with not explicitly binding since WPF will assume you intended to put it in the ContentPresenter! But all the other button properties are going to be ignored. For example, if you try changing the Background property of your templated button, it will be ignored because WPF doesn’t know where to put that background. Should it be the whole control? Should it be your grid? Just your ContentPresenter? You have to tell it.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.