Page 1 of 1

Unable to change button font size

Posted: 18 Sep 2019, 07:52
by asusralis
What could cause not being able to change a button's font size? I have a button style defined in my Resources, and all properties set in it change every button except the font size. I have a TextBlock style that sets its FontSize to a static resource, but removing that does not help things. I can't find any other button style it could be using, so I'm confused as to why buttons refuse to change their text size.

Re: Unable to change button font size

Posted: 18 Sep 2019, 13:19
by sfernandez
I tried the following xaml in our XamlPlayer to test different ways to define the FontSize and Button content and all behave as expected:
<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid.Resources>
        <Style x:Key="btnStyle" TargetType="Button">
            <Setter Property="FontSize" Value="20"/>
        </Style>
        <ControlTemplate x:Key="btnTemp" TargetType="Button">
            <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                <TextBlock Text="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Border>
        </ControlTemplate>
    </Grid.Resources>
    <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
        <Button Content="Button" FontSize="20"/>
        <Button FontSize="20">
            <TextBlock Text="Button"/>
        </Button>
        <Button Content="Button" Style="{StaticResource btnStyle}"/>
        <Button Content="Button" Template="{StaticResource btnTemp}" FontSize="20"/>
    </StackPanel>
</Grid>
What could you have different in your styles+xaml?

Re: Unable to change button font size

Posted: 18 Sep 2019, 22:49
by asusralis
These are the only relevant styles in my resources:
    <Style x:Name="TextBlockStyle" TargetType="TextBlock">
        <Setter Property="Foreground" Value="{StaticResource FontColor}" />
        <Setter Property="FontFamily" Value="{StaticResource Font}" />
        <Setter Property="FontSize" Value="{StaticResource FontSize.Medium}" />
    </Style>

    <Style TargetType="Button">
        <Setter Property="FontSize" Value="{StaticResource FontSize.Medium}" />
        <Setter Property="Background" Value="Pink"/>
    </Style>
The background of the button changes, but the font size does not. However, the background does turn pink. If I understand correctly, buttons use a TextBlock which means I wouldn't have to set the font size in the button style? Either way, setting the font size on a specific button also does not change its font size.
                    <Button
                        Content="Text"
                        FontSize="72" />
I've searched my entire project but there are no other button or text block styles.

Re: Unable to change button font size

Posted: 18 Sep 2019, 23:26
by sfernandez
I tested the following xaml in Unity and the Button changes its size correctly:
<Grid
  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">
    <Grid.Resources>
        <sys:Double x:Key="FontSize.Medium">72</sys:Double>
        <Style TargetType="Button">
            <Setter Property="FontSize" Value="{StaticResource FontSize.Medium}"/>
            <Setter Property="Background" Value="Pink"/>
        </Style>
    </Grid.Resources>
    <Button Content="Text" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
Is it possible that you have the Buttons inside a Viewbox, so no matter what font size you set, the Buttons always stretch to fill the Viewbox?

Re: Unable to change button font size

Posted: 19 Sep 2019, 00:06
by asusralis
There are no ViewBoxes in the project. It's odd because I don't remember ever being able to change a button text size in this project - created a few months ago - but creating a new project allows me to change button font sizes like normal.

This is all that is happening in a specific view I've tested:
<UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Assets/Project/Views/Resources.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Button Content="Test" FontSize="60"/>
    </Grid>
I have styles in my resources for scrollviewers, progressbars, listboxes, tooltips... But I don't see how they would affect any of this. I've shown you the only two styles in my resources that have to do with textblocks and buttons.

Re: Unable to change button font size

Posted: 24 Sep 2019, 09:39
by sfernandez
but creating a new project allows me to change button font sizes like normal.
Could you add to that new project (the one working) the resources from the old project (a few every time) to determine which one is causing this issue?

Re: Unable to change button font size

Posted: 09 Jan 2020, 12:48
by asusralis
It seems when I remove my TextBlock style I can set the button's FontSize, but when it's there I cannot.
    <Style TargetType="TextBlock">
        <Setter Property="FontSize" Value="{StaticResource FontSize.Normal}" />
        <Setter Property="FontFamily" Value="{StaticResource Font}" />
        <Setter Property="Foreground" Value="White" />
    </Style>
    
     <Style TargetType="Button">
        <Setter Property="FontSize" Value="{StaticResource FontSize.Normal}" />
        <Setter Property="FontFamily" Value="{StaticResource Font}" />
    </Style>
    ...
    
    <StackPanel>
            <StackPanel.Resources>
                <Style BasedOn="{StaticResource {x:Type Button}}" TargetType="Button">
                    <Setter Property="FontSize" Value="{StaticResource FontSize.VeryLarge}" />
                </Style>
            </StackPanel.Resources>
            <Button Content="My Text"/>
        </StackPanel>
    
In this example, setting the FontSize in the derived implicit (?) style declared in the StackPanel or directly to the "My Text" button does not change its FontSize unless I remove the implicit style declared in my main Resources.

Re: Unable to change button font size

Posted: 16 Jan 2020, 11:56
by sfernandez
Would you mind creating a ticket in our bugtracker and attach your project (it can be a private ticket if you need to)?
Everything I test here works as expected and I'm not able to reproduce that problem.

Thanks for your collaboration.

Re: Unable to change button font size

Posted: 30 Mar 2021, 14:22
by asusralis
By the way, I found a fix to this problem. I created a few projects with Noesis last week, brand new, and this problem existed; even without a custom button style. After searching it for WPF, I found I had to add this to change a button's font size:
    <DataTemplate DataType="{x:Type sys:String}">
        <TextBlock Text="{Binding}">
            <TextBlock.Resources>
                  <Style TargetType="{x:Type TextBlock}" />
            </TextBlock.Resources>
        </TextBlock>
    </DataTemplate>
Do you not need this to change a button's font size in your projects?

Edit: Although, if I try set this TextBlock Style's 'default' FontSize, or if I base it implicitly off of a TextBlock Style that sets the FontSize, I'm now unable again to directly set a Button's FontSize.

Re: Unable to change button font size

Posted: 30 Mar 2021, 16:26
by sfernandez
Could you please create a ticket and attach one of those projects or a new small one that reproduces the issue?
I want to analyze the specific scenario where this is happening to see if it behaves as in WPF or if it is something wrong in Noesis.
Everything I try myself doesn't break the possibility to set the FontSize in a Button (locally or via a Style setter).