Page 1 of 1

Noesis 2 button template content alignment

Posted: 04 Mar 2017, 10:34
by monstercho
Noticed another difference between Noesis 1.2.6f5 and v2. If I set this theme:
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:sys="clr-namespace:System;assembly=mscorlib">
	
	<Color x:Key="PhoneForegroundColor">#FFFFFFFF</Color>
	<SolidColorBrush x:Key="PhoneForegroundBrush" Color="{StaticResource PhoneForegroundColor}" />
	
	<Style TargetType="Button">
		<Setter Property="Background" Value="Transparent"/>
		<Setter Property="BorderBrush" Value="{StaticResource PhoneForegroundBrush}"/>
		<Setter Property="BorderThickness" Value="2"/>
		<Setter Property="FontSize" Value="18"/>
		<Setter Property="Padding" Value="10,5,10,6"/>
		<Setter Property="Template">
		  <Setter.Value>
			<ControlTemplate TargetType="Button">
			  <Grid Background="Transparent">
				<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="2" CornerRadius="0" Margin="5">
				  <ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
				</Border>
			  </Grid>
			</ControlTemplate>
		  </Setter.Value>
		</Setter>
	</Style>
</ResourceDictionary>
And define button:
<Button Content="OK" Margin="139,322,131,0" Height="92" Width="220" />
Button text "OK" is centered in Noesis 1.2.6f2, but top-left aligned in 2.0.

I can easily center it using content alignment, but maybe it's something worth reporting.

Simple projects:
Noesis2.0.0f1: https://drive.google.com/file/d/0B1zHz_ ... sp=sharing
Noesis1.2.6f5: https://drive.google.com/file/d/0B1zHz_ ... sp=sharing

Re: Noesis 2 button template content alignment

Posted: 07 Mar 2017, 19:12
by sfernandez
Hi,

In NoesisGUI 1.2 the dictionary you set in NoesisGUIPanel Style property was added as a merged dictionary to the xaml root. This means that styles were used as the implicity style (position 5) in the value precedence list. So properties not defined in your style obtain their value from our internal default (Theme) style.

In NoesisGUI 2.0 the Theme dictionary you set in NoesisSettings is used to override the default (Theme) style (position 9 in value precendence list). So properties not defined in your style obtain their value from the default value defined by the dependency property.

In your example, HorizontalContentAlignment and VerticalContentAlignment properties have a default value of Left and Top respectively. If you don't override them in your Theme style, that is the value they will get.

I added the following to your theme style and now it works the way you want:
<Style TargetType="Button">
  <Setter Property="HorizontalContentAlignment" Value="Center"/>
  <Setter Property="VerticalContentAlignment" Value="Center"/>
  ...
</Style>

Re: Noesis 2 button template content alignment

Posted: 07 Mar 2017, 20:38
by monstercho
Thanks for the precedence list info