So I tried different ways and nothing worked. Finally I tried a SendWait to send an ENTER key, and it worked. Here is the code. Note that since I've hidden the ChartTrader control grid in which the text box resides, I had to unhide it for the moment, because if the text box is hidden it can't gain focus.
ChartControl.Dispatcher.InvokeAsync((() =>
{
AccountSelector acctsel = (Window.GetWindow(ChartControl.Parent) as Chart).FindFirst("ChartTraderControlAccountSelecto r") as AccountSelector;
acctsel.SelectedAccount = Account.All.First(a => a.Name == Account.Name);
TextBox quantityTextBox = (Window.GetWindow(ChartControl.Parent) as Chart).FindFirst("ChartTraderControlQuantityEdit") as TextBox;
string text = (Tgt1Quantity + Tgt2Quantity + Tgt3Quantity).ToString();
if (text != quantityTextBox.Text)
{
ChartTraderControlGrid1.Visibility = Visibility.Visible;
quantityTextBox.Focus();
quantityTextBox.Text = text;
System.Windows.Forms.SendKeys.SendWait("{ENTER}");
ChartTraderControlGrid1.Visibility = Visibility.Collapsed;
}
}));

Comment