Reputation: 255
I want to set the font size of my labels to the value of a slider!
My slider is on another page and each label is on its own page!
My slider page bind to ChangeSizeViewModel, but my labels bind to my database table!
How can I bind the fonts of my labels to the value of the slider, considering that each one has its own place?
Thank you in advance to those who help me!
The following code is my slider code:
<Slider x:Name="sLiDer" MaximumTrackColor="Red" Value="{Binding ChangeSize }" Maximum="50" Minimum="20"/ >
The following code is my Label code:
<Label x:Name="tozih" Text="{Binding Description}" FontAttributes="Bold" />
Upvotes: 0
Views: 52
Reputation: 10356
How can I bind the fonts of my labels to the value of the slider, considering that each one has its own place?
I suggest you can create global variables public static double in App.xaml.cs.
public static double labelsize;
public App()
{
InitializeComponent();
MainPage =new NavigationPage( new simplecontrol.Page8());
}
Then using Slider_ValueChanged event to pass slider value to App.labelsize. You also assign slider first value to App.labelsize in ContentPage constructor.
Slider on Page:
<StackLayout>
<Slider
x:Name="sLiDer"
Maximum="50"
MaximumTrackColor="Red"
Minimum="20"
ValueChanged="sLiDer_ValueChanged"
Value="{Binding ChangeSize}" />
<Button
x:Name="btn2"
Clicked="btn2_Clicked"
Text="navigate to another page" />
</StackLayout>
public Page8()
{
InitializeComponent();
App.labelsize = sLiDer.Value;
}
private void sLiDer_ValueChanged(object sender, ValueChangedEventArgs e)
{
double value = ((Slider)sender).Value;
App.labelsize = value;
}
On other labelPage,you get slider value, you can using binding or other ways to set Label Fontsize.
public Page1()
{
InitializeComponent();
double fontsize = App.labelsize;
}
Upvotes: 1