Never expose the fields
or controls of a form to other parts of your code. If you do, you??™ll quickly wind up with a tightly coupled interface
where one window reaches deep into the inner workings of another, and you won??™t be able to enhance
either class without breaking the murky interdependencies between them.
Single-Instance Applications
Ordinarily, you can launch as many copies of a WPF application as you want. In some scenarios,
this design makes perfect sense. However, in other cases it??™s a problem, particularly when
building document-based applications.
For example, consider Microsoft Word. No matter how many documents you open (or
how you open them), only a single instance of winword.exe is loaded at a time. As you open
new documents, they appear in the new windows, but a single application remains in control
of all the document windows. This design is the best approach if you want to reduce the overhead
of your application, centralize certain features (for example, create a single print queue
manager), or integrate disparate windows (for example, offer a feature that tiles all the currently
open document windows next to each other).
CHAPTER 3 n THE APPLICATION 69
WPF doesn??™t provide a native solution for single-instance applications, but you can use
several workarounds.
Pages:
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186