Download binary file - here
Download source files - here
WPF presents new way to implement visual appearance of application. We can implement it in XAML and C# files both or separately. We use Application.LoadComponent( Object, Uri ) method for load XAML files where "Uri" presents way to XAML file. So we can manipulate visual appearance presented in XAML's files load different XAML's files.
Note: We can't use x:Class attribute for root node in XAML's files. In this case compiler automatic generates C# code (in *.g.cs file) and those classes will be conflicted (more precisely - some automatic generated members will be conflicted). Thus we can't use x:Code and describe to events in XAML's files (code for support those actions were implemented in *.g.cs files).
Note: Class have been generated in XAML's file (more precisely - in *.g.cs) is normal class likes class have been generated in C# code and even we can inherit a custom class from it.
My sample presents two mode for manager and worker that to show the personal's information. We load different XAML's files against of mode. First we show dialog window that propose to choose behaviour.
Different XAML's contains different class instants for present data:
PeopleEx (People - for worker) - presents data of personnel (less for worker and more for manager).
ManagerInfoPresenter (WorkerInfoPresenter - for worker) - get a information (different for other mode).
ManagerCapacityShow (WorkerCapacityShow - for worker) - show a diagram. It is fake but it is different for other mode.
We can implement different controls with one name in other XAML's files (for example "InformCheck" or "CapacityShow"). We found those controls in XAML's files to use FindName(String) method and we can handle some events of this controls.
CheckBox informer = (CheckBox)FindName( INFORMCHECK_NAME );
informer.Checked += new RoutedEventHandler( OnInformerChecked );
informer.Unchecked += new RoutedEventHandler( OnInformerUnchecked );
We can apply to different class members to use base class (like m_CapacityShow member) or interface (like m_InfoPresenter member).
if( AppMode.Manager == appMode )
m_InfoPresenter = new ManagerInfoPresenter();
m_InfoPresenter = new WorkerInfoPresenter();
m_CapacityShow = (Image)FindName( CAPACITYSHOW_NAME );
We can really create one class window for two (or more) behaviour of application. We don't hide any controls or elements we don't load they! It is elegant way to dynamic create application.