Hi guys,
I have created a button template consisting of a border and a content presenter. A style is then wrapped around this template and applied to a button, when this button is used it is not carrying the values for horizontal and vertical alignment. In the designer the allignments are showing and the button is in the correct place, but when i run the program the button appears to have horizontal alignment = left and vertical alignment = right. Any ideas?
here is the code for the template:
<ControlTemplate TargetType="Button" x:Key="DefaultButtonTemplate">
<Border CornerRadius="4"
Background="{TemplateBinding Background}"
BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}">
<Grid>
<ContentPresenter ContentSource="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"/>
</Grid>
</Border>
</ControlTemplate>
Here is the code for the style:
<Style TargetType="Button">
<Setter Property="Background" Value="{DynamicResource WindowHeaderBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource WindowBorderBrush}" />
<Setter Property="Template" Value="{DynamicResource DefaultButtonTemplate}" />
<Setter Property="BorderThickness" Value="1" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{DynamicResource ButtonHoverBrush}" />
<Setter Property="BitmapEffect" Value="{DynamicResource ButtonHoverGlow}" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="{DynamicResource ButtonPressedBrush}" />
</Trigger>
</Style.Triggers>
</Style>
And here is the code for the button :)
<Button Name="button1" Height="31" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="0,0,10,10">Button</Button>
There is no code behind file
The result of this code is a button that appears in the TOP LEFT corner of the parent flat up against the edge