Hi I am working in WPF C# application and I am new.
In my application, there is a stack panel, lets call this stack panel as first stack panel. This stack panel has one text box whose width and height are not set. It has margin of 100. Its text wrapping is set to wrap.
User provides text information in to the text box. If user want more text box, then there is a button. Upon clicking this button, a new text box with previous text box properties appears in the first stack panel and user continuous typing.
The main goal is to show, the print preview of the first stack panel while user typing text into the text boxes of the first stack panel.
So what I did is: I have another stack panel, lets call this second stack panel beside to the first stack panel. There is function or method which is called upon each key press. This function or method, collects all the text from each text box from first stack panel into a list (of type string) and then it adds each string from the list as textblock (children) to second stackpanel. And once all the string from the list added to the second stackpanel, the textbox from the first stackpanel gets back focus so that user can able to continue typing text.
So far It is working fine. The problem is, as user adds more textboxes, it takes longer time to appear in the second stackpanel and set back the focus to the textbox from first stack panel.
To over come the situation, I used the following code:
private void OnPreviewKeyUp(object sender, KeyEventArgs e){
//code to collect text from each textbox from first stackpanel and add into a list of type string.
this.Dispatcher.Invoke(()=> {
ReloadTextInfoToPanel(textBoxTextList);
});
}
the above code, still taking same amount of time. I even tried using
this.Dispatcher.InvokeAsync();
But same amount of time it is consuming.
What I want is, when user is typing in the text boxes of first stack panel then the function or method should be called independently, with out blocking the control.
I hope you have understood, what is the issue. Pardon my Bad English. Please guide me. Thanks in advance.
ReloadTextInfoToPanel. If you use MVVM concepts here (Data Binding) you should be able avoid interrupting the user at all. So show us your code and we can provide you a more efficient routine. - Chris Schaller