SAE
New member
- Joined
- Mar 19, 2022
- Messages
- 4
- Programming Experience
- Beginner
The Idea is that when I start the application 2 windows pop up. On mainwindow I have button and on window1 I have label and when I press the button the label color should change.
This is what Far have tried so far but it didn't work. What am I doing wrong ? and how to make it work ?
Note: in the wpf app am not using Model View ViewModel.
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void btnFirstWindow_Click(object sender, RoutedEventArgs e)
{
Window1 sWindow = new Window1(btnFirstWindow);
sWindow.Show();
}
}
Mainwindow XAML
Title="MainWindow" Height="450" Width="800">
<Grid>
<Button x:Name="btnFirstWindow" Content="Button" HorizontalAlignment="Left" Height="140" Margin="492,77,0,0" VerticalAlignment="Top" Width="151" Click="btnFirstWindow_Click"/>
</Grid>
**
public partial class Window1 : Window
{
private Button btnfirstWindow;
public Window1(Button btnfirstWindow)
{
this.btnfirstWindow = btnfirstWindow;
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
btnfirstWindow.Click += btnfirstWindow_Click;
}
void btnfirstWindow_Click(object sender, RoutedEventArgs e)
{
lblShowUser.Background = Brushes.Red;
}
}
** Window1 XAML**
Title="Window1" Height="450" Width="800">
<Grid>
<Label Name="lblShowUser" Content="Label" HorizontalAlignment="Left" Height="119" Margin="321,98,0,0" VerticalAlignment="Top" Width="281"/>
</Grid>
This is what Far have tried so far but it didn't work. What am I doing wrong ? and how to make it work ?
Note: in the wpf app am not using Model View ViewModel.
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void btnFirstWindow_Click(object sender, RoutedEventArgs e)
{
Window1 sWindow = new Window1(btnFirstWindow);
sWindow.Show();
}
}
Mainwindow XAML
Title="MainWindow" Height="450" Width="800">
<Grid>
<Button x:Name="btnFirstWindow" Content="Button" HorizontalAlignment="Left" Height="140" Margin="492,77,0,0" VerticalAlignment="Top" Width="151" Click="btnFirstWindow_Click"/>
</Grid>
**
public partial class Window1 : Window
{
private Button btnfirstWindow;
public Window1(Button btnfirstWindow)
{
this.btnfirstWindow = btnfirstWindow;
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
btnfirstWindow.Click += btnfirstWindow_Click;
}
void btnfirstWindow_Click(object sender, RoutedEventArgs e)
{
lblShowUser.Background = Brushes.Red;
}
}
** Window1 XAML**
Title="Window1" Height="450" Width="800">
<Grid>
<Label Name="lblShowUser" Content="Label" HorizontalAlignment="Left" Height="119" Margin="321,98,0,0" VerticalAlignment="Top" Width="281"/>
</Grid>
Last edited: