public Window1()
{
InitializeComponent();
textBox.KeyDown += OnTextBoxKeyDown;
}
private void OnTextBoxKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.B
&& (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
{
string boldText = "**";
int beginMarkerIndex = textBox.SelectionStart;
int endMarkerIndex = beginMarkerIndex + textBox.SelectionLength + boldText.Length;
textBox.Text = textBox.Text.Insert(beginMarkerIndex, boldText)
.Insert(endMarkerIndex, boldText);
}
}