admin管理员组文章数量:1417691
I want to change the font for all TextBox controls in WinUI 3, but it is not working as expected. I specified the font in the ResourceDictionary of App as follows, but it was not applied to some controls, particularly TextBox, NumberBox, and the MenuFlyout of Button.
App.xaml
<?xml version="1.0" encoding="utf-8"?>
<Application
x:Class="App1.App"
xmlns=";
xmlns:x=";
xmlns:local="using:App1">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<!-- Other merged dictionaries here -->
</ResourceDictionary.MergedDictionaries>
<!-- Other app resources here -->
<FontFamily x:Key="XamlAutoFontFamily">Arial Black</FontFamily>
<FontFamily x:Key="ContentControlThemeFontFamily">Arial Black</FontFamily>
<FontFamily x:Key="MTCMediaFontFamily">Arial Black</FontFamily>
<FontFamily x:Key="PhoneFontFamilyNormal">Arial Black</FontFamily>
<FontFamily x:Key="PhoneFontFamilySemiLight">Arial Black</FontFamily>
<FontFamily x:Key="PivotHeaderItemFontFamily">Arial Black</FontFamily>
<FontFamily x:Key="PivotTitleFontFamily">Arial Black</FontFamily>
<FontFamily x:Key="SymbolThemeFontFamily">Segoe Fluent Icons,Segoe MDL2 Assets</FontFamily>
<FontFamily x:Key="KeyTipFontFamily"></FontFamily>
<Style TargetType="TextBox">
<Setter Property="FontFamily" Value="Arial Black" />
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
XAML
<?xml version="1.0" encoding="utf-8"?>
<Window
x:Class="App1.MainWindow"
xmlns=";
xmlns:x=";
xmlns:local="using:App1"
xmlns:d=";
xmlns:mc=";
mc:Ignorable="d"
Title="App1">
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Content="Show Menu"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Margin="0,50,0,0">
<Button.Flyout>
<MenuFlyout>
<MenuFlyoutItem Text="Option 1" />
</MenuFlyout>
</Button.Flyout>
</Button>
<TextBox HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,50" Width="200" Text="Enter text here"/>
</StackPanel>
</Window>
I understand that I can set FontFamily individually, but if anyone knows how to apply the font to TextBox and the MenuFlyout of Button, please let me know.
I want to change the font for all TextBox controls in WinUI 3, but it is not working as expected. I specified the font in the ResourceDictionary of App as follows, but it was not applied to some controls, particularly TextBox, NumberBox, and the MenuFlyout of Button.
App.xaml
<?xml version="1.0" encoding="utf-8"?>
<Application
x:Class="App1.App"
xmlns="http://schemas.microsoft/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft/winfx/2006/xaml"
xmlns:local="using:App1">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<!-- Other merged dictionaries here -->
</ResourceDictionary.MergedDictionaries>
<!-- Other app resources here -->
<FontFamily x:Key="XamlAutoFontFamily">Arial Black</FontFamily>
<FontFamily x:Key="ContentControlThemeFontFamily">Arial Black</FontFamily>
<FontFamily x:Key="MTCMediaFontFamily">Arial Black</FontFamily>
<FontFamily x:Key="PhoneFontFamilyNormal">Arial Black</FontFamily>
<FontFamily x:Key="PhoneFontFamilySemiLight">Arial Black</FontFamily>
<FontFamily x:Key="PivotHeaderItemFontFamily">Arial Black</FontFamily>
<FontFamily x:Key="PivotTitleFontFamily">Arial Black</FontFamily>
<FontFamily x:Key="SymbolThemeFontFamily">Segoe Fluent Icons,Segoe MDL2 Assets</FontFamily>
<FontFamily x:Key="KeyTipFontFamily"></FontFamily>
<Style TargetType="TextBox">
<Setter Property="FontFamily" Value="Arial Black" />
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
XAML
<?xml version="1.0" encoding="utf-8"?>
<Window
x:Class="App1.MainWindow"
xmlns="http://schemas.microsoft/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats./markup-compatibility/2006"
mc:Ignorable="d"
Title="App1">
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Content="Show Menu"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Margin="0,50,0,0">
<Button.Flyout>
<MenuFlyout>
<MenuFlyoutItem Text="Option 1" />
</MenuFlyout>
</Button.Flyout>
</Button>
<TextBox HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,50" Width="200" Text="Enter text here"/>
</StackPanel>
</Window>
I understand that I can set FontFamily individually, but if anyone knows how to apply the font to TextBox and the MenuFlyout of Button, please let me know.
Share Improve this question edited Feb 1 at 13:48 kinton asked Jan 31 at 8:03 kintonkinton 3151 silver badge7 bronze badges 6- Not reproducible. Please provide minimal reproducible example. – emoacht Commented Jan 31 at 13:38
- Change to a more detailed sample code. – kinton Commented Feb 1 at 11:34
- It doesn't reproduce. Arial Black in <Style TargetType="TextBox"> in App.xaml is applied to the TextBox in MainWindow.xaml. BTW, FontFamily definitions in App.xaml seem irrelevant to reproduce the issue. – emoacht Commented Feb 1 at 12:21
- Thank you for checking. So, it works fine on your end, emoacht. I simply created a new WinUI app and applied the code from my question, but for some reason, it doesn't seem to take effect... I'm using Windows App SDK 1.6.250108002. – kinton Commented Feb 1 at 13:56
- I just realized that specifying FontFamily directly on a TextBox doesn't seem to take effect... Hmm. – kinton Commented Feb 1 at 14:01
1 Answer
Reset to default 0I was able to do it with <TextBox Text="Enter text here" FontFamily="Arial" FontWeight="Black"/>
, so I will go with this.
本文标签: xamlHow to change the font of a TextBox in WinUI3Stack Overflow
版权声明:本文标题:xaml - How to change the font of a TextBox in WinUI3 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745275556a2651163.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论