title: Content alignment and positioning in templated wpf control
body: <p>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:</p>
  
  <p>I wrote the following template to completely change the appearance of my buttons:</p>
  
  <pre><code>    &lt;ControlTemplate TargetType="{x:Type Button}" x:Key="ImageButtonTemplate"&gt;
          &lt;Grid&gt;
              &lt;Image Name="img" Source="/PSPlayer;component/Images/Buttons/ButtonNormal_normal.png"/&gt;
              &lt;ContentPresenter Stylus.IsTapFeedbackEnabled="False" Stylus.IsTouchFeedbackEnabled="False" Stylus.IsPressAndHoldEnabled="False" Stylus.IsFlicksEnabled="False" Width="98" Height="61"/&gt;
          &lt;/Grid&gt;
  
          &lt;ControlTemplate.Triggers&gt;
              &lt;Trigger Property="IsMouseOver" Value="True"&gt;
                  &lt;Setter TargetName="img" Property="Source" Value="/PSPlayer;component/Images/Buttons/ButtonNormal_MouseOver.png"/&gt;
              &lt;/Trigger&gt;
              &lt;Trigger Property="IsPressed" Value="True"&gt;
                  &lt;Setter TargetName="img" Property="Source" Value="/PSPlayer;component/Images/Buttons/ButtonNormal_MouseDown.png"/&gt;
              &lt;/Trigger&gt;
          &lt;/ControlTemplate.Triggers&gt;
      &lt;/ControlTemplate&gt;
  </code></pre>
  
  <p>and here a button definition:</p>
  
  <pre><code>        &lt;Button Content="SomeText" Height="61" Margin="0,0,0,7" Name="button7" Width="98" Click="button7_Click" Template="{StaticResource ImageButtonTemplate}"/&gt;
  </code></pre>
  
  <p>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).</p>
  
  <p>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.</p>
  
  <p>I made a walkaround with a label embedded inside the button that I could position but think there must be a cleaner solution.</p>
  
  <p>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) :)</p>
  
  <p>Thanks in advance,</p>
  
  <p>Julian</p>