I made a switch on which the program should change all backgrounds of gieven elements. Therefore I made a new changer-class (View Model) which accesses every xaml file and changes the background color:
TheView1.xaml: (partial)
<ScrollView
x:Name="myScrollView" [...]
TheView1.xaml.cs: (partial)
void switch_Toggled(object sender, ToggledEventArgs e)
{
if (themeSwitch.IsToggled)
{
ChangeBackground.ChangeColor();
}
}
ChangeBackgrounds.cs
public static class ChangeBackground
{
TheView1 tv1 = new TheView1();
public static void ChangeColor()
{
tv1.myScrollView.BackgroundColor = [...];
tv1.myButton.BackgroundColor = [...];
}
}
VS then says "tv1 does not contain a definition for myScrollView and myButton". But they are clearly there, why does´nt it work?