I’m trying to convert code from a WFA (Windows Form Application) over to a WPF. However, i’m running into many difficulties. There is no .MaxLength. There is also no .Text as there is when using a Windows Form Application. How would i re-write the following code for WPF?
xbox is refering to a box on a chat window where the user types in text….
PS. The code below DOES work for WFA….
private void BoxChatAreaKeyPress(object sender, KeyPressEventArgs e)
{
var xBox = (RichTextBox) sender;
//setting a limit so the user cannot type more than 4000 characters at once
xBox.MaxLength = 4000;
if ((xBox.Text.Length > 1) && (e.KeyChar == (char) Keys.Enter))
{
WriteMessage(xBox);
}
}
private static void WriteMessage(RichTextBox xBox)
{
var writer = new StreamWriter(_client.GetStream());
String message = xBox.Text.TrimEnd('\n') + "|" + _font.Name;
writer.WriteLine(message);
writer.Flush();
xBox.Text = null;
}
This is what I came up with: