wpfui
wpfui copied to clipboard
Button FontSize ineffective
Describe the bug
<Button Content="Button1" FontSize="100" /> fontsize ineffective . nuget version Preview.9 is OK, Preview 10,11,12,13 all can be reproduced.
To Reproduce
minimal project ,https://github.com/IOL0ol1/WpfUITest.git
Expected behavior
plz fixed it
Screenshots
OS version
Windows 11 Pro 22H2 (22621.3007)
.NET version
net6.0-windows net8.0-windows
WPF-UI NuGet version
3.0.0-preview.13 3.0.0-preview.12 3.0.0-preview.11 3.0.0-preview.10
Additional context
Preview.9 is OK, Preview 10,11,12,13 all can be reproduced
Can confirm. Font Size
affects icons instead. The "Font Size" property in Icon="{ui:SymbolIcon Person24, FontSize=24}"
does not work as well.
Can confirm.
Font Size
affects icons instead. The "Font Size" property inIcon="{ui:SymbolIcon Person24, FontSize=24}"
does not work as well.
Perhaps all Content has this issue
Can confirm.
Font Size
affects icons instead. The "Font Size" property inIcon="{ui:SymbolIcon Person24, FontSize=24}"
does not work as well.Perhaps all Content has this issue
seems so, can confirm it only works on icons and not button text
I am not experiencing any issue with changing the font size of any control. Perhaps you are not configuring the project the right way? Tested with Preview.13
@frostybee here is my test VS solution: https://github.com/IOL0ol1/WpfUITest.git, What is the effect of your operation?
here is my MainWindow : Windows 11 Pro 22H2 (22621.3007) WPF-UI 3.0.0-preview.13
@frostybee @SouljaVR @NoThrottle @timheuer hi, everyone.
This is a temporary solution: Copy the styles in the source code and strip out the font size settings
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ui:ThemesDictionary Theme="Dark" />
<ui:ControlsDictionary />
</ResourceDictionary.MergedDictionaries>
<Style TargetType="{x:Type TextBlock}">
<!--<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}"/>-->
<!-- The Display option causes a large aliasing effect -->
<!--<Setter Property="TextOptions.TextFormattingMode" Value="Ideal" />-->
<Setter Property="Background" Value="Transparent" />
<Setter Property="Margin" Value="0" />
<Setter Property="Padding" Value="0" />
<Setter Property="Focusable" Value="False" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="True" />
</Style>
</ResourceDictionary>
</Application.Resources>
or just use the system default style
<Style TargetType="{x:Type TextBlock}" BasedOn="{x:Null}">
in TextBlock.xaml a default font size is set. It could be that ContentControl uses a TextBlock to render text.
https://github.com/lepoco/wpfui/blob/7fcc2d8410f056d1d6de97c2f8078b3d8b38539b/src/Wpf.Ui/Controls/TextBlock/TextBlock.xaml#L17
Perhaps the font size should be removed from the Wpf.Ui/Controls/TextBlock/TextBlock.xaml
@frostybee I've added minimal test code https://github.com/IOL0ol1/WpfUITest
@frostybee I've added minimal test code https://github.com/IOL0ol1/WpfUITest
Yes, I saw your test code. However, you are not using the WPF UI controls the right way. Please refer to my previous message to see an example of how you should do it.
@frostybee Well, I use your diagram directly, so you think the font size of the red rectangular area is normal?
@IOL0ol1 @NoThrottle @SouljaVR @timheuer I guess I found a fix.
I just added the following to the ResourceDictionary in App.xaml and it worked.
<DataTemplate DataType="{x:Type sys:String}">
<TextBlock Text="{Binding}">
<TextBlock.Resources>
<Style TargetType="{x:Type TextBlock}"/>
</TextBlock.Resources>
</TextBlock>
</DataTemplate>
The cause of this problem is explained here: https://stackoverflow.com/questions/4284513/wpf-change-fontsize-of-button-with-style-fails
So here is the output:
@frostybee
I just added the following to the ResourceDictionary in App.xaml and it worked.
<DataTemplate DataType="{x:Type sys:String}"> <TextBlock Text="{Binding}"> <TextBlock.Resources> <Style TargetType="{x:Type TextBlock}"/> </TextBlock.Resources> </TextBlock> </DataTemplate>
This breaks the accesibility feature (Alt+letter) in MenuItem
instances.
Can confirm.
Font Size
affects icons instead. The "Font Size" property inIcon="{ui:SymbolIcon Person24, FontSize=24}"
does not work as well.
The symbolicon markup extension got updated and should work now. For the button itself, i will look into it. I found out about this only some days ago.
I have searched in the web, they say override DataTemplate for System.String is not good idea:
https://ikriv.com/dev/wpf/TextStyle/#TextBlockStyle
and you can also see this one:
https://stackoverflow.com/questions/4500115/default-textblock-style-overriding-button-text-color
the explain about the implicit TextBlock style article is:
Why implicit TextBlock style takes over everything
so the simple way is redefining the button Content as explicit TextBlock:
<Button Width="200">
<TextBlock Foreground="Blue" FontStyle="Italic" Text="Blue Italic Button" />
</Button>
@taijifeng @m0lDaViA Maybe it would be better to change WPFUI's global TextBlock style to a named style.
I have searched in the web, they say override DataTemplate for System.String is not good idea: https://ikriv.com/dev/wpf/TextStyle/#TextBlockStyle and you can also see this one: https://stackoverflow.com/questions/4500115/default-textblock-style-overriding-button-text-color the explain about the implicit TextBlock style article is: Why implicit TextBlock style takes over everything so the simple way is redefining the button Content as explicit TextBlock:
<Button Width="200">
<TextBlock Foreground="Blue" FontStyle="Italic" Text="Blue Italic Button" />
</Button>
Can you update your links please?
@taijifeng @m0lDaViA Maybe it would be better to change WPFUI's global TextBlock style to a named style.
What do you mean by "named" style?
@m0lDaViA Just like MahApps.Metro, add x:key for TextBlocks, and set the Style directly when you use it.As @taijifeng said, not overwriting the global TextBlock is the optimal solution.
https://github.com/MahApps/MahApps.Metro/blob/509c9d7e559025754854e4472db3b3adaaf9ef38/src/MahApps.Metro/Styles/Controls.TextBlock.xaml#L4
@m0lDaViA Just like MahApps.Metro, add x:key for TextBlocks, and set the Style directly when you use it.As @taijifeng said, not overwriting the global TextBlock is the optimal solution.
MahApps/MahApps.Metro@
509c9d7
/src/MahApps.Metro/Styles/Controls.TextBlock.xaml#L4
The problem is that the button uses a contentpresenter to present the text inside. The question is if we only should be able to present text as the buttons content or not. If we only present text we can simply change the contentpresenter to a textbox which can use the fontsize property. But i don't know if it is a contentpresenter to add the possibility of using different types of content.
So, i've tested this now a lot and you cannot set the fontsize of the text simple because any text value in Content="Text" does get set directly as string.
You could use
<ui:Button HorizontalIconAlignment="Right" FontSize="20" > <ui:Button.Content> <TextBlock Text="12312321"></TextBlock> </ui:Button.Content> <ui:Button.Icon> <ui:FontIcon Glyph="🌈" FontSize="25" /> </ui:Button.Icon> </ui:Button>
In this case the fontsize property gets honored. We could also simply change the contentpresenter to a textblock. But this depends on if the button should be able to handle other types of content. But together you cannot change the fontsize of the text input.
I think it is better to wait for @pomianowski to responde to this and telling us what he want to have.
Edit: you could also hack your way around this with multiple templates but tbh?
Hey, the button should definitely accept whatever the ContentPresenter
accepts, so the issue of default FontSize
should be solved in a different way
Hey, the button should definitely accept whatever the
ContentPresenter
accepts, so the issue of defaultFontSize
should be solved in a different way
So in that case we should create another template and switch between them?
So i can offer the following: If you use Content="Text" it get's formatted by the button properties itself and if you create a textblock in the content property you need to bind the fontsize to the button or set it directly there. Otherwise it is not possible. Is that ok @pomianowski ?
EDIT: couldn't we just swap ContentPresenter with ContentControl?
@m0lDaViA Placing a grid inside a button that contains multiple TextBlocks and TextBoxes, with some using the button's font size and others using a specified font size, and further nesting other controls (including buttons) within the grid—will this be too complicated to handle?
@m0lDaViA Placing a grid inside a button that contains multiple TextBlocks and TextBoxes, with some using the button's font size and others using a specified font size, and further nesting other controls (including buttons) within the grid—will this be too complicated to handle?
For inside the resource dictionary or you?^^
@m0lDaViA Sorry for my terrible English, I mean the content of the button can be placed with anything, isn't it easier to give the global textblock style a key than other solutions
@m0lDaViA Sorry for my terrible English, I mean the content of the button can be placed with anything, isn't it easier to give the global textblock style a key than other solutions
Sure you could but you could also just use Content="Text" which get's formatted based on the parent control.