我們有2把窗戶打開,就像一個聊天發送信息WPF窗口
這是文本框什麼,該按鈕看起來像:
private void textBox_chat_TextChanged(object sender, TextChangedEventArgs e)
{
}
private void button_enviar_Click(object sender, RoutedEventArgs e)
{
string chatMessage = textBox_chat.Text;
}
我想知道如何通過按下「button_enviar」按鈕來發送文本框中的信息。並打印到其他窗口。 我一直在尋找像Application.Current.Windows
...但仍然沒有找到辦法。
我的代碼實際上是這樣的:
主窗口
namespace WpfApplication1
{
/// <summary>
/// Lógica de interacción para MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
// automatic code generated by the button
private void button_entrar_Click(object sender, RoutedEventArgs e)
{
// we catch the taxt input in the texBox
string userLoginName = textBox_pantalla_inicial.Text;
// We call the chat window
Window window1 = new Window1();
// we put the user name as the title of the chat window
window1.Title = userLoginName;
// show the chat window
window1.Show();
}
}
}
ChatWindow
namespace WpfApplication1
{
/// <summary>
/// Lógica de interacción para Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
// inicialize chatWindow
InitializeComponent();
}
private void textBox_chat_TextChanged(object sender, TextChangedEventArgs e)
{
}
private void button_enviar_Click(object sender, RoutedEventArgs e)
{
string chatMessage = textBox_chat.Text;
}
private void button_erase_Click(object sender, RoutedEventArgs e)
{
}
}
}
你可以看看你的應用程序中託管一個WCF服務並調用服務來顯示消息。 –
WCF - Windows Communication Foundation https://msdn.microsoft.com/en-us/library/ms731082(v=vs.110).aspx在.NET中查找聊天教程 – Paparazzi
感謝您的反饋,但需要解決方案完全在本地工作... – Qu4k3