**
I have 2 windows in app. mainwindow with 2 buttons and window1 with a label. btn one opens window1 and btn 2 changes window1 label color.
**
public partial class MainWindow : Window
{
Window1 sWindow = new Window1();public MainWindow()
{InitializeComponent();
}
private void btnFirstWindow_Click(object sender, RoutedEventArgs e)
{
sWindow.Show();
}
private void btnChangeBackground_Click_1(object sender, RoutedEventArgs e)
{
sWindow.ChangeBackground();
}
}
public partial class Window1 : Window {
public Window1()
{
InitializeComponent();
}
public void ChangeBackground()
{
if (lblShowUser.Background == Brushes.Green)
{
lblShowUser.Background = new LinearGradientBrush(Colors.Red, Colors.Red, 90);
}
else
{
lblShowUser.Background = Brushes.Green;
}
}
}
IF I remove this part **
private void btnFirstWindow_Click(object sender, RoutedEventArgs e) { sWindow.Show(); } ** From mainwindow and add both windows at app xaml Startup="App_Startup" StartupUri="MainWindow.xaml">public partial class App : Application { void App_Startup(object sender, StartupEventArgs e) { Window1 sWindow = new Window1();
sWindow.Show();
}
}
the method of label changing color when i press the other button doesnt work am new to C# and wpf So when answering please also give explantion on what to be done to the code and why
expecting it to work even if changes are made regarding when the other page shows up but its not working
