Ana, segue:
EdicaoAgencia.xaml
<Window x:Class="ByteBank.Agencias.EdicaoAgencia"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ByteBank.Agencias"
mc:Ignorable="d"
Title="EdicaoAgencia" Height="300" Width="470.667">
<Canvas>
<StackPanel Canvas.Top="15" Canvas.Left="15" Width="270">
<TextBlock FontWeight="Bold">Número</TextBlock>
<local:ValidacaoTextBox x:Name="txtNumero"></local:ValidacaoTextBox>
<TextBlock FontWeight="Bold">Nome</TextBlock>
<local:ValidacaoTextBox x:Name="txtNome"></local:ValidacaoTextBox>
<TextBlock FontWeight="Bold">Telefone</TextBlock>
<local:ValidacaoTextBox x:Name="txtTelefone"></local:ValidacaoTextBox>
<TextBlock FontWeight="Bold">Descrição</TextBlock>
<local:ValidacaoTextBox x:Name="txtDescricao"></local:ValidacaoTextBox>
<TextBlock FontWeight="Bold">Endereço</TextBlock>
<local:ValidacaoTextBox x:Name="txtEndereco"></local:ValidacaoTextBox>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Canvas.Left="225" Canvas.Top="231" Width="228">
<Button Name="btnOK" Content="OK" Margin="15,0" Padding="5" Width="85"></Button>
<Button Name="btnCancelar" Content="Cancelar" Margin="15,0" Padding="5" Width="84"/>
</StackPanel>
</Canvas>
</Window>
EdicaoAgencia.xaml.cs
using ByteBank.Agencias.DAL;
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 ByteBank.Agencias
{
/// <summary>
/// Lógica interna para EdicaoAgencia.xaml
/// </summary>
public partial class EdicaoAgencia : Window
{
private readonly Agencia _agencia;
public EdicaoAgencia(Agencia agencia)
{
InitializeComponent();
_agencia = agencia ?? throw new ArgumentNullException(nameof(agencia));
AtualizarControles();
AtualizarCamposDeTexto();
}
private void AtualizarControles()
{
RoutedEventHandler dialogResultTrue = (o, e) => DialogResult = true;
RoutedEventHandler dialogResultFalse = (o, e) => DialogResult = false;
var okEventHandler = dialogResultTrue + Fechar;
var cancelarEventHandler = dialogResultFalse + Fechar;
btnOK.Click += okEventHandler;
btnCancelar.Click += cancelarEventHandler;
txtNumero.TextChanged += ValidarCampoNulo;
txtNumero.TextChanged += ValidarSomenteDigito;
txtNome.TextChanged += ValidarCampoNulo;
txtTelefone.TextChanged += ValidarCampoNulo;
txtDescricao.TextChanged += ValidarCampoNulo;
txtEndereco.TextChanged += ValidarCampoNulo;
}
private void ValidarSomenteDigito(object sender, EventArgs e)
{
var txt = sender as TextBox;
var textoEstaVazio = txt.Text.All(Char.IsDigit);
txt.Background = textoEstaVazio
? new SolidColorBrush(Colors.White)
: new SolidColorBrush(Colors.Pink);
}
private void ValidarCampoNulo(object sender, EventArgs e)
{
var txt = sender as TextBox;
var textoEstaVazio = String.IsNullOrEmpty(txt.Text);
txt.Background = textoEstaVazio
? new SolidColorBrush(Colors.OrangeRed)
: new SolidColorBrush(Colors.White);
}
private void Fechar(object sender, RoutedEventArgs e) => Close();
private void AtualizarCamposDeTexto()
{
txtNumero.Text = _agencia.Numero.Trim();
txtNome.Text = _agencia.Nome.Trim();
txtTelefone.Text = _agencia.Telefone.Trim();
txtEndereco.Text = _agencia.Endereco.Trim();
txtDescricao.Text = _agencia.Descricao.Trim();
}
}
}