There is no DynamicResource in WinUI
You can just change the font size by code by naming the TextBlock
<TextBlock x:Name="TextBlock1"
then
TextBlock1.FontSize = controlsize;
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi
i am creating sample Winui3 packaged application in c# i need textblock fontsize dynamically calculate with screen resulation please suggest me. the below piece of code working fine for WPF but not Winui3 is there any alternative to this?
private void Window_Loaded(object sender, RoutedEventArgs e)
{
double controlsize = ((SystemParameters.PrimaryScreenWidth / 12) / 3 * 2) / 5 * 0.7;
System.Windows.Application.Current.Resources.Remove("ControlFontSize");
System.Windows.Application.Current.Resources.Add("ControlFontSize", controlsize);
}
Step3 : In the Xaml page use FontSize="{DynamicResource ControlFontSize}" for the control like:
<TextBlock Text="Button" HorizontalAlignment="Left" FontSize="{DynamicResource ControlFontSize}"
Margin="239,163,0,0" VerticalAlignment="Top" Width="75"/>
There is no DynamicResource in WinUI
You can just change the font size by code by naming the TextBlock
<TextBlock x:Name="TextBlock1"
then
TextBlock1.FontSize = controlsize;