Replies: 3 comments
-
xaml: <TextBlock x:Name="CodeBehindExample" Text="This is another way of doing it" /> code-behind: private int _lastWidthBreakPoint = -1;
public MainPage()
{
this.InitializeComponent();
this.SizeChanged += (s, e) =>
{
var breakpoint = e.NewSize.Width switch
{
var x when x >= 1920 => 1920,
//var x when x >= 1080 => 1080, // if you have more breakpoints, add like so
_ => 0,
};
if (breakpoint != _lastWidthBreakPoint)
{
if (breakpoint == 0)
{
CodeBehindExample.FontSize = 10; // note: you may want to match this value with default textbox fontsize
}
//else if (breakpoint == 1080) { } // if you have more breakpoints, add like so
else if (breakpoint == 1920)
{
CodeBehindExample.FontSize = 35;
}
// store the last used breakpoint, so we only update when moving to another breakpoint
_lastWidthBreakPoint = breakpoint;
}
};
} |
Beta Was this translation helpful? Give feedback.
-
Additionally, you can also use the responsive extension from toolkit: xmlns:utu="using:Uno.Toolkit.UI"
...
<TextBlock Text="This is another way of doing it" FontSize="{utu:Responsive Normal=10, Widest=35}">
<TextBlock.Resources>
<utu:ResponsiveLayout x:Key="WidestAt1920" Widest="1920" />
</TextBlock.Resources>
</TextBlock> note1: Here, I am using a local layout override at the control level for simplicity, but you can also define this globally.
note3: this feature is not supported on uwp (for windows) |
Beta Was this translation helpful? Give feedback.
-
thank you this helped to solve my problem |
Beta Was this translation helpful? Give feedback.
-
I've added a textbox and made the font size responsive by adding the "FontSize" binding like the below.
Using adaptive triggers this works nicely for different screen sizes in xaml
Is there a way I can add the
FontSize
binding of my textbox using c# only ?thanks
<TextBlock x:Name="CustomMyFont" Text="This is a sample" FontSize="{Binding FontSize, ElementName=CustomMyFont, Mode=TwoWay}"/>
Beta Was this translation helpful? Give feedback.
All reactions