// LoginWindow.xaml.cs
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace WpfApp18
{
    public partial class LoginWindow : Window
    {
        public LoginWindow()
        {
            InitializeComponent();
            ApplySettings();
            UsernameTextBox.Focus();
            PasswordTextBox.Tag = "Password";
        }

        private void ApplySettings()
        {
            SetBackgroundColor(AppState.Settings.BackgroundColor);
            UpdateLanguage(AppState.Settings.Language);
        }

        private void SetBackgroundColor(string color)
        {
            switch (color)
            {
                case "Red":
                    this.Background = new SolidColorBrush(Colors.LightPink);
                    break;
                case "Yellow":
                    this.Background = new SolidColorBrush(Colors.LightYellow);
                    break;
                case "Green":
                    this.Background = new SolidColorBrush(Colors.LightGreen);
                    break;
                default:
                    this.Background = new SolidColorBrush(Colors.White);
                    break;
            }
        }

        private void UpdateLanguage(string language)
        {
            switch (language)
            {
                case "ru":
                    this.Title = "Вход";
                    ShowPasswordCheckBox.Content = "Показать пароль";
                    ((TextBlock)UsernameTextBox.Template.FindName("placeholder", UsernameTextBox)).Text = "Имя пользователя";
                    PasswordTextBox.Tag = "Пароль";
                    LoginButton.Content = "Войти";
                    break;
                case "by":
                    this.Title = "Уваход";
                    ShowPasswordCheckBox.Content = "Паказаць пароль";
                    ((TextBlock)UsernameTextBox.Template.FindName("placeholder", UsernameTextBox)).Text = "Імя карыстальніка";
                    PasswordTextBox.Tag = "Пароль";
                    LoginButton.Content = "Увайсці";
                    break;
                default: // en
                    this.Title = "Login";
                    ShowPasswordCheckBox.Content = "Show Password";
                    ((TextBlock)UsernameTextBox.Template.FindName("placeholder", UsernameTextBox)).Text = "Username";
                    PasswordTextBox.Tag = "Password";
                    LoginButton.Content = "Login";
                    break;
            }
        }

        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void ShowPasswordCheckBox_Checked(object sender, RoutedEventArgs e)
        {
            PasswordTextBox.Text = PasswordBox.Password;
            PasswordBox.Visibility = Visibility.Collapsed;
            PasswordTextBox.Visibility = Visibility.Visible;
        }

        private void ShowPasswordCheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
            PasswordBox.Password = PasswordTextBox.Text;
            PasswordTextBox.Visibility = Visibility.Collapsed;
            PasswordBox.Visibility = Visibility.Visible;
        }

        private void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            // Add your login logic here
            string username = UsernameTextBox.Text;
            string password = PasswordBox.Visibility == Visibility.Visible ?
                            PasswordBox.Password :
                            PasswordTextBox.Text;

            if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
            {
                MessageBox.Show("Please enter both username and password.", "Login Error");
                return;
            }

            // Here you would typically validate the credentials against a database
            // For this example, we'll just show a success message
            MessageBox.Show("Login successful!", "Success");
            this.Close();
        }
    }
}<Window x:Class="WpfApp18.LoginWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Login" Height="300" Width="400"
        WindowStartupLocation="CenterScreen">
    <Window.Resources>
        <Style x:Key="FormTextBoxStyle" TargetType="TextBox">
            <Setter Property="Width" Value="200"/>
            <Setter Property="Height" Value="30"/>
            <Setter Property="Margin" Value="5"/>
            <Setter Property="Padding" Value="5"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="BorderBrush" Value="#bdc3c7"/>
            <Setter Property="Foreground" Value="Black"/>
            <Style.Triggers>
                <Trigger Property="Text" Value="">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="TextBox">
                                <Border Background="{TemplateBinding Background}"
                                        BorderBrush="{TemplateBinding BorderBrush}"
                                        BorderThickness="{TemplateBinding BorderThickness}"
                                        Padding="{TemplateBinding Padding}">
                                    <Grid>
                                        <TextBlock x:Name="placeholder"
                                                 Text="Username" 
                                                 Foreground="Gray"
                                                 IsHitTestVisible="False"
                                                 Margin="2,0,0,0"
                                                 VerticalAlignment="Center"/>
                                        <ScrollViewer x:Name="PART_ContentHost"
                                                    Focusable="false"
                                                    HorizontalScrollBarVisibility="Hidden"
                                                    VerticalScrollBarVisibility="Hidden"/>
                                    </Grid>
                                </Border>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="FormPasswordBoxStyle" TargetType="PasswordBox">
            <Setter Property="Width" Value="200"/>
            <Setter Property="Height" Value="30"/>
            <Setter Property="Margin" Value="5"/>
            <Setter Property="Padding" Value="5"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="BorderBrush" Value="#bdc3c7"/>
        </Style>

        <Style x:Key="FormButtonStyle" TargetType="Button">
            <Setter Property="Width" Value="100"/>
            <Setter Property="Height" Value="30"/>
            <Setter Property="Margin" Value="5"/>
            <Setter Property="Background" Value="#2ecc71"/>
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border Background="{TemplateBinding Background}"
                                CornerRadius="3"
                                BorderThickness="1"
                                BorderBrush="#27ae60">
                            <ContentPresenter HorizontalAlignment="Center" 
                                            VerticalAlignment="Center"/>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="#27ae60"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>

    <Grid>
        <Button x:Name="CloseButton"
                Content="✕" 
                HorizontalAlignment="Right" 
                VerticalAlignment="Top"
                Width="30" 
                Height="30"
                Click="CloseButton_Click"
                Background="Transparent"
                BorderThickness="0"/>

        <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
            <TextBox x:Name="UsernameTextBox" 
                     Style="{StaticResource FormTextBoxStyle}"/>

            <Grid>
                <PasswordBox x:Name="PasswordBox" 
                            Style="{StaticResource FormPasswordBoxStyle}"
                            Visibility="Visible"/>
                <TextBox x:Name="PasswordTextBox"
                        Style="{StaticResource FormTextBoxStyle}"
                        Visibility="Collapsed"/>
            </Grid>

            <CheckBox x:Name="ShowPasswordCheckBox" 
                      Content="Show Password"
                      Margin="5"
                      Checked="ShowPasswordCheckBox_Checked"
                      Unchecked="ShowPasswordCheckBox_Unchecked"/>

            <Button x:Name="LoginButton"
                    Content="Login" 
                    Style="{StaticResource FormButtonStyle}"
                    Click="LoginButton_Click"/>
        </StackPanel>
    </Grid>
</Window><Window x:Class="WpfApp18.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Welcome" Height="400" Width="400"
        WindowStartupLocation="CenterScreen"
        x:Name="MainWin">
    <Window.Resources>
        <Style x:Key="MainButtonStyle" TargetType="Button">
            <Setter Property="Width" Value="150"/>
            <Setter Property="Height" Value="40"/>
            <Setter Property="Margin" Value="10"/>
            <Setter Property="Background" Value="#3498db"/>
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="FontSize" Value="14"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border Background="{TemplateBinding Background}"
                                CornerRadius="5"
                                BorderThickness="1"
                                BorderBrush="#2980b9">
                            <ContentPresenter HorizontalAlignment="Center" 
                                            VerticalAlignment="Center"/>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="#2980b9"/>
                </Trigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="LanguageButtonStyle" TargetType="Button">
            <Setter Property="Width" Value="40"/>
            <Setter Property="Height" Value="40"/>
            <Setter Property="Margin" Value="5"/>
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="BorderBrush" Value="#2980b9"/>
        </Style>

        <Style x:Key="ColorButtonStyle" TargetType="Button">
            <Setter Property="Width" Value="30"/>
            <Setter Property="Height" Value="30"/>
            <Setter Property="Margin" Value="5"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="BorderBrush" Value="Black"/>
        </Style>
    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Language Selection -->
        <StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,10">
            <Button x:Name="EnglishButton" Style="{StaticResource LanguageButtonStyle}" Click="EnglishButton_Click" 
                    Content="EN"/>
            <Button x:Name="RussianButton" Style="{StaticResource LanguageButtonStyle}" Click="RussianButton_Click"
                    Content="RU"/>
            <Button x:Name="BelarusianButton" Style="{StaticResource LanguageButtonStyle}" Click="BelarusianButton_Click"
                    Content="BY"/>
        </StackPanel>

        <!-- Color Selection -->
        <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,10">
            <Button x:Name="RedButton" Style="{StaticResource ColorButtonStyle}" Background="Red" 
                    Click="RedButton_Click"/>
            <Button x:Name="YellowButton" Style="{StaticResource ColorButtonStyle}" Background="Yellow" 
                    Click="YellowButton_Click"/>
            <Button x:Name="GreenButton" Style="{StaticResource ColorButtonStyle}" Background="Green" 
                    Click="GreenButton_Click"/>
        </StackPanel>

        <!-- Main Buttons -->
        <StackPanel Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Center">
            <Button x:Name="LoginBtn" Content="Login" Style="{StaticResource MainButtonStyle}"
                    Click="LoginButton_Click"/>
            <Button x:Name="RegisterBtn" Content="Register" Style="{StaticResource MainButtonStyle}"
                    Click="RegisterButton_Click"/>
        </StackPanel>
    </Grid>
</Window><Window x:Class="WpfApp18.RegisterWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Register" Height="350" Width="400"
        WindowStartupLocation="CenterScreen">
    <Window.Resources>
        <Style x:Key="FormTextBoxStyle" TargetType="TextBox">
            <Setter Property="Width" Value="200"/>
            <Setter Property="Height" Value="30"/>
            <Setter Property="Margin" Value="5"/>
            <Setter Property="Padding" Value="5"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="BorderBrush" Value="#bdc3c7"/>
            <Setter Property="Foreground" Value="Black"/>
            <Style.Triggers>
                <Trigger Property="Text" Value="">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="TextBox">
                                <Border Background="{TemplateBinding Background}"
                                        BorderBrush="{TemplateBinding BorderBrush}"
                                        BorderThickness="{TemplateBinding BorderThickness}"
                                        Padding="{TemplateBinding Padding}">
                                    <Grid>
                                        <TextBlock x:Name="placeholder"
                                                 Text="{Binding Path=Tag, RelativeSource={RelativeSource TemplatedParent}}"
                                                 Foreground="Gray"
                                                 IsHitTestVisible="False"
                                                 Margin="2,0,0,0"
                                                 VerticalAlignment="Center"/>
                                        <ScrollViewer x:Name="PART_ContentHost"
                                                    Focusable="false"
                                                    HorizontalScrollBarVisibility="Hidden"
                                                    VerticalScrollBarVisibility="Hidden"/>
                                    </Grid>
                                </Border>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="FormPasswordBoxStyle" TargetType="PasswordBox">
            <Setter Property="Width" Value="200"/>
            <Setter Property="Height" Value="30"/>
            <Setter Property="Margin" Value="5"/>
            <Setter Property="Padding" Value="5"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="BorderBrush" Value="#bdc3c7"/>
        </Style>

        <Style x:Key="FormButtonStyle" TargetType="Button">
            <Setter Property="Width" Value="100"/>
            <Setter Property="Height" Value="30"/>
            <Setter Property="Margin" Value="5"/>
            <Setter Property="Background" Value="#e74c3c"/>
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border Background="{TemplateBinding Background}"
                                CornerRadius="3"
                                BorderThickness="1"
                                BorderBrush="#c0392b">
                            <ContentPresenter HorizontalAlignment="Center" 
                                            VerticalAlignment="Center"/>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="#c0392b"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>

    <Grid>
        <Button x:Name="CloseButton"
                Content="✕" 
                HorizontalAlignment="Right" 
                VerticalAlignment="Top"
                Width="30" 
                Height="30"
                Click="CloseButton_Click"
                Background="Transparent"
                BorderThickness="0"/>

        <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
            <TextBox x:Name="UsernameTextBox" 
                     Style="{StaticResource FormTextBoxStyle}"
                     Tag="Username"/>

            <Grid>
                <PasswordBox x:Name="PasswordBox" 
                            Style="{StaticResource FormPasswordBoxStyle}"
                            Visibility="Visible"/>
                <TextBox x:Name="PasswordTextBox"
                        Style="{StaticResource FormTextBoxStyle}"
                        Tag="Password"
                        Visibility="Collapsed"/>
            </Grid>

            <Grid>
                <PasswordBox x:Name="ConfirmPasswordBox" 
                            Style="{StaticResource FormPasswordBoxStyle}"
                            Visibility="Visible"/>
                <TextBox x:Name="ConfirmPasswordTextBox"
                        Style="{StaticResource FormTextBoxStyle}"
                        Tag="Confirm Password"
                        Visibility="Collapsed"/>
            </Grid>

            <CheckBox x:Name="ShowPasswordCheckBox" 
                      Content="Show Password"
                      Margin="5"
                      Checked="ShowPasswordCheckBox_Checked"
                      Unchecked="ShowPasswordCheckBox_Unchecked"/>

            <Button x:Name="RegisterButton"
                    Content="Register" 
                    Style="{StaticResource FormButtonStyle}"
                    Click="RegisterButton_Click"/>
        </StackPanel>
    </Grid>
</Window>using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace WpfApp18
{
    public partial class RegisterWindow : Window
    {
        public RegisterWindow()
        {
            InitializeComponent();
            ApplySettings();
            UsernameTextBox.Focus();
            PasswordTextBox.Tag = "Password";
            ConfirmPasswordTextBox.Tag = "Confirm Password";
        }

        private void ApplySettings()
        {
            SetBackgroundColor(AppState.Settings.BackgroundColor);
            UpdateLanguage(AppState.Settings.Language);
        }

        private void SetBackgroundColor(string color)
        {
            switch (color)
            {
                case "Red":
                    this.Background = new SolidColorBrush(Colors.LightPink);
                    break;
                case "Yellow":
                    this.Background = new SolidColorBrush(Colors.LightYellow);
                    break;
                case "Green":
                    this.Background = new SolidColorBrush(Colors.LightGreen);
                    break;
                default:
                    this.Background = new SolidColorBrush(Colors.White);
                    break;
            }
        }

        private void UpdateLanguage(string language)
        {
            switch (language)
            {
                case "ru":
                    this.Title = "Регистрация";
                    ShowPasswordCheckBox.Content = "Показать пароль";
                    ((TextBlock)UsernameTextBox.Template.FindName("placeholder", UsernameTextBox)).Text = "Имя пользователя";
                    PasswordTextBox.Tag = "Пароль";
                    ConfirmPasswordTextBox.Tag = "Подтвердите пароль";
                    RegisterButton.Content = "Зарегистрироваться";
                    break;
                case "by":
                    this.Title = "Рэгістрацыя";
                    ShowPasswordCheckBox.Content = "Паказаць пароль";
                    ((TextBlock)UsernameTextBox.Template.FindName("placeholder", UsernameTextBox)).Text = "Імя карыстальніка";
                    PasswordTextBox.Tag = "Пароль";
                    ConfirmPasswordTextBox.Tag = "Пацвердзіце пароль";
                    RegisterButton.Content = "Зарэгістравацца";
                    break;
                default: // en
                    this.Title = "Register";
                    ShowPasswordCheckBox.Content = "Show Password";
                    ((TextBlock)UsernameTextBox.Template.FindName("placeholder", UsernameTextBox)).Text = "Username";
                    PasswordTextBox.Tag = "Password";
                    ConfirmPasswordTextBox.Tag = "Confirm Password";
                    RegisterButton.Content = "Register";
                    break;
            }
        }

        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void ShowPasswordCheckBox_Checked(object sender, RoutedEventArgs e)
        {
            PasswordTextBox.Text = PasswordBox.Password;
            ConfirmPasswordTextBox.Text = ConfirmPasswordBox.Password;
            PasswordBox.Visibility = Visibility.Collapsed;
            ConfirmPasswordBox.Visibility = Visibility.Collapsed;
            PasswordTextBox.Visibility = Visibility.Visible;
            ConfirmPasswordTextBox.Visibility = Visibility.Visible;
        }

        private void ShowPasswordCheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
            PasswordBox.Password = PasswordTextBox.Text;
            ConfirmPasswordBox.Password = ConfirmPasswordTextBox.Text;
            PasswordTextBox.Visibility = Visibility.Collapsed;
            ConfirmPasswordTextBox.Visibility = Visibility.Collapsed;
            PasswordBox.Visibility = Visibility.Visible;
            ConfirmPasswordBox.Visibility = Visibility.Visible;
        }

        private void RegisterButton_Click(object sender, RoutedEventArgs e)
        {
            string username = UsernameTextBox.Text;
            string password = PasswordBox.Visibility == Visibility.Visible ?
                            PasswordBox.Password :
                            PasswordTextBox.Text;
            string confirmPassword = ConfirmPasswordBox.Visibility == Visibility.Visible ?
                                   ConfirmPasswordBox.Password :
                                   ConfirmPasswordTextBox.Text;

            if (string.IsNullOrWhiteSpace(username) ||
                string.IsNullOrWhiteSpace(password) ||
                string.IsNullOrWhiteSpace(confirmPassword))
            {
                MessageBox.Show("Please fill in all fields.", "Registration Error");
                return;
            }

            if (password != confirmPassword)
            {
                MessageBox.Show("Passwords do not match.", "Registration Error");
                return;
            }

            // Here you would typically save the user to a database
            // For this example, we'll just show a success message
            MessageBox.Show("Registration successful!", "Success");
            this.Close();
        }
    }
}System.NullReferenceException: "Ссылка на объект не указывает на экземпляр объекта."using System.Windows; using System.Windows.Media; using System.Windows.Controls; namespace WpfApp18 { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); ApplySettings(); } private void ApplySettings() { SetLanguage(AppState.Settings.Language); SetBackgroundColor(AppState.Settings.BackgroundColor); } private void SetLanguage(string language) { switch (language) { case "ru": this.Title = "Добро пожаловать"; LoginBtn.Content = "Вход"; RegisterBtn.Content = "Регистрация"; break; case "by": this.Title = "Сардэчна запрашаем"; LoginBtn.Content = "Уваход"; RegisterBtn.Content = "Рэгістрацыя"; break; default: // en this.Title = "Welcome"; LoginBtn.Content = "Login"; RegisterBtn.Content = "Register"; break; } } private void SetBackgroundColor(string color) { switch (color) { case "Red": this.Background = new SolidColorBrush(Colors.LightPink); break; case "Yellow": this.Background = new SolidColorBrush(Colors.LightYellow); break; case "Green": this.Background = new SolidColorBrush(Colors.LightGreen); break; default: this.Background = new SolidColorBrush(Colors.White); break; } } private void EnglishButton_Click(object sender, RoutedEventArgs e) { SetLanguage("en"); AppState.UpdateLanguage("en"); } private void RussianButton_Click(object sender, RoutedEventArgs e) { SetLanguage("ru"); AppState.UpdateLanguage("ru"); } private void BelarusianButton_Click(object sender, RoutedEventArgs e) { SetLanguage("by"); AppState.UpdateLanguage("by"); } private void RedButton_Click(object sender, RoutedEventArgs e) { SetBackgroundColor("Red"); AppState.UpdateBackgroundColor("Red"); } private void YellowButton_Click(object sender, RoutedEventArgs e) { SetBackgroundColor("Yellow"); AppState.UpdateBackgroundColor("Yellow"); } private void GreenButton_Click(object sender, RoutedEventArgs e) { SetBackgroundColor("Green"); AppState.UpdateBackgroundColor("Green"); } private void LoginButton_Click(object sender, RoutedEventArgs e) { LoginWindow loginWindow = new LoginWindow(); loginWindow.Owner = this; loginWindow.ShowDialog(); } private void RegisterButton_Click(object sender, RoutedEventArgs e) { RegisterWindow registerWindow = new RegisterWindow(); registerWindow.Owner = this; registerWindow.ShowDialog(); } } } namespace WpfApp18 { public class User { public string Username { get; set; } public string Password { get; set; } } }using System; using System.Configuration; namespace WpfApp18 { public class Settings { public string Language { get; set; } = "en"; public string BackgroundColor { get; set; } = "White"; } public static class AppState { public static Settings Settings { get; private set; } = new Settings(); public static void UpdateLanguage(string language) { Settings.Language = language; SaveSettings(); } public static void UpdateBackgroundColor(string color) { Settings.BackgroundColor = color; SaveSettings(); } private static void SaveSettings() { // Here you would typically save settings to a file or database // For this example, we'll just keep them in memory } } } The NullReferenceException is occurring when trying to access the placeholder TextBlock in the TextBox template. This happens because the template might not be applied yet when we're trying to update the text. Let's fix this by modifying both the XAML and code-behind approach. WRITE THE WHOLE FULL CORRECTED CODE FOR EVERY FILE