wpfui icon indicating copy to clipboard operation
wpfui copied to clipboard

Button FontSize ineffective

Open IOL0ol1 opened this issue 1 year ago • 25 comments

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

image

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

IOL0ol1 avatar Dec 20 '23 13:12 IOL0ol1

Can confirm. Font Size affects icons instead. The "Font Size" property in Icon="{ui:SymbolIcon Person24, FontSize=24}" does not work as well.

NoThrottle avatar Dec 23 '23 07:12 NoThrottle

Can confirm. Font Size affects icons instead. The "Font Size" property in Icon="{ui:SymbolIcon Person24, FontSize=24}" does not work as well.

Perhaps all Content has this issue

IOL0ol1 avatar Dec 25 '23 08:12 IOL0ol1

Can confirm. Font Size affects icons instead. The "Font Size" property in Icon="{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

SouljaVR avatar Jan 03 '24 07:01 SouljaVR

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

image

frostybee avatar Jan 24 '24 00:01 frostybee

@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

image

IOL0ol1 avatar Jan 25 '24 10:01 IOL0ol1

@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

IOL0ol1 avatar Jan 25 '24 11:01 IOL0ol1

@frostybee I've added minimal test code https://github.com/IOL0ol1/WpfUITest

IOL0ol1 avatar Jan 25 '24 14:01 IOL0ol1

@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 avatar Jan 25 '24 14:01 frostybee

@frostybee Well, I use your diagram directly, so you think the font size of the red rectangular area is normal? image

IOL0ol1 avatar Jan 25 '24 15:01 IOL0ol1

@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:

image

frostybee avatar Jan 25 '24 19:01 frostybee

@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.

sntg-p avatar Feb 20 '24 00:02 sntg-p

Can confirm. Font Size affects icons instead. The "Font Size" property in Icon="{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.

m0lDaViA avatar May 10 '24 01:05 m0lDaViA

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 avatar Jun 07 '24 02:06 taijifeng

@taijifeng @m0lDaViA Maybe it would be better to change WPFUI's global TextBlock style to a named style.

IOL0ol1 avatar Jun 07 '24 02:06 IOL0ol1

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 avatar Jun 08 '24 03:06 m0lDaViA

@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

IOL0ol1 avatar Jun 08 '24 03:06 IOL0ol1

@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.

m0lDaViA avatar Jun 10 '24 09:06 m0lDaViA

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="&#x1F308;" 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?

m0lDaViA avatar Jun 10 '24 12:06 m0lDaViA

Hey, the button should definitely accept whatever the ContentPresenter accepts, so the issue of default FontSize should be solved in a different way

pomianowski avatar Jun 10 '24 13:06 pomianowski

Hey, the button should definitely accept whatever the ContentPresenter accepts, so the issue of default FontSize should be solved in a different way

So in that case we should create another template and switch between them?

m0lDaViA avatar Jun 10 '24 13:06 m0lDaViA

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 avatar Jun 20 '24 14:06 m0lDaViA

@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?

IOL0ol1 avatar Jun 20 '24 15:06 IOL0ol1

@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 avatar Jun 20 '24 15:06 m0lDaViA

@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

IOL0ol1 avatar Jun 20 '24 17:06 IOL0ol1

@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.

m0lDaViA avatar Jun 20 '24 21:06 m0lDaViA