I'm new to WPF. I am attempting to modify the indicator 'SampleWPFModifications.cs'. My goal is to place 2 TextBlocks and 2 TextBoxes on the ChartTrader. In the attached screenshot the controls are showing. When I try to type in either textbox the Instrument Selection box appears. I added the code from 'TextBox.cs' that addresses the PreviewKeyDown event.
else if (State == State.Historical)
{
// Because we're dealing with UI elements, we need to use the Dispatcher which created the object
// in order for us to update the contents that are created on the main UI thread
Dispatcher.Invoke((() =>
{
textBox = new TextBox();
textBox.PreviewKeyDown += TextBox_PreviewKeyDown;
UserControlCollection.Add(textBox);
}));
}
private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
// this is pretty dumb, but should get you started
// might want to validate this by using SHIFT or something
// so Overlay Instrument Selector isn't unusable...
TextBox textBoxSender = (TextBox) sender;
textBoxSender.Text += e.Key.ToString();
// handle the keydown event for the text box
e.Handled = true;
}
Dispatcher.Invoke((() =>
{
chartTraderCustomTextBoxArray[0] = new TextBox()
{
FontFamily = ChartControl.Properties.LabelFont.Family,
FontSize = 13,
Foreground = ChartControl.Properties.ChartText,
HorizontalAlignment = HorizontalAlignment.Left,
Margin = new Thickness(5, 5, 5, 5),
Text = string.Format("{0} ", shareQuantity)
};
//textBox.PreviewKeyDown += TextBox_PreviewKeyDown;
chartTraderCustomTextBoxArray[0].PreviewKeyDown += SampleWPFModifications_PreviewKeyDownOne;
UserControlCollection.Add(textBox);
}));
private void SampleWPFModifications_PreviewKeyDownOne(object sender, System.Windows.Input.KeyEventArgs e)
{
// this is pretty dumb, but should get you started
// might want to validate this by using SHIFT or something
// so Overlay Instrument Selector isn't unusable...
TextBox textBoxSender = (TextBox)sender;
textBoxSender.Text += e.Key.ToString();
// handle the keydown event for the text box
e.Handled = true;
}
Thanks in advance for any suggestions.

Comment