Best Way to show Busy Bar In WPF Application
I have WPF Application where I have One main form and other user controls are shown in the main form as child form. I have to show Busy bar when I make Async call to data base. What is the best way to declare Busy bar object and then used in every child user control. Should I need to declare busy bar object in the main Form and then Used it t开发者_JS百科he child user control or The App file is best, or is there any good way.
It depends on whether your "busy bar" is a control that appears inside other controls or windows, or a popup window in its own right.
If it's a control, you cannot (easily) use a single control instance in multiple places in the application. A WPF control instance is part of a visual and logical tree. It cannot be part of two visual trees. You can create a BusyBar control class, and declare multiple instances of that in the various places you need it: to do this, use the User Control (WPF) or Custom Control (WPF) template in Visual Studio.
If it's a window, you can create it during application startup but leave it hidden. Then you can show it from code when required (using the Show or ShowDialog method). That said, it's not clear why you'd need this to be a singleton anyway. Creating windows is cheap, especially compared to calls across a network to a database. Again, declaring a class, and creating and showing instances of the class when required, would be the more usual approach. You could easily create a static method to encapsulate the "create-bind-show-wait-hide" cycle so as not to pollute your app code with the details.
精彩评论