Unable to change button font size
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.
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Unable to change button font size
I tried the following xaml in our XamlPlayer to test different ways to define the FontSize and Button content and all behave as expected:
What could you have different in your styles+xaml?
Code: Select all
<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>
Re: Unable to change button font size
These are the only relevant styles in my resources:
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.
I've searched my entire project but there are no other button or text block styles.
Code: Select all
<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>
Code: Select all
<Button
Content="Text"
FontSize="72" />
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Unable to change button font size
I tested the following xaml in Unity and the Button changes its size correctly:
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?
Code: Select all
<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>
Re: Unable to change button font size
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:
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.
This is all that is happening in a specific view I've tested:
Code: Select all
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Assets/Project/Views/Resources.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Button Content="Test" FontSize="60"/>
</Grid>
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Unable to change button font size
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?but creating a new project allows me to change button font sizes like normal.
Re: Unable to change button font size
It seems when I remove my TextBlock style I can set the button's FontSize, but when it's there I cannot.
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.
Code: Select all
<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>
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Unable to change button font size
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.
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
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:
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.
Code: Select all
<DataTemplate DataType="{x:Type sys:String}">
<TextBlock Text="{Binding}">
<TextBlock.Resources>
<Style TargetType="{x:Type TextBlock}" />
</TextBlock.Resources>
</TextBlock>
</DataTemplate>
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.
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Unable to change button font size
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).
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).
Who is online
Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 65 guests