using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApp2
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void OpenGreeting_Click(object sender, RoutedEventArgs e)
{
}
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
}
private void Button_Click(object sender, RoutedEventArgs e)
{
TextBox nameBox = this.Content as TextBox;
if (nameBox == null)
{
Grid mainGrid = this.Content as Grid;
if (mainGrid != null)
{
foreach (var child in mainGrid.Children)
{
if (child is TextBox)
{
nameBox = (TextBox)child;
break;
}
}
}
}
string userName = nameBox != null ? nameBox.Text : "";
Window1 secondWindow = new Window1(userName);
secondWindow.Show();
}
}
}
//2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace WpfApp2
{
public partial class Window1 : Window
{
public Window1(string name)
{
InitializeComponent();
Grid mainGrid = this.Content as Grid;
if (mainGrid != null)
{
foreach (var child in mainGrid.Children)
{
if (child is TextBlock)
{
TextBlock textBlock = (TextBlock)child;
textBlock.Text = $"Привет, {name}!";
break;
}
}
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
MessageBox.Show("Вы нажали 'Спасибо'!");
this.Close();
}
}
}