I am creating a application, in which i have 2 user control, is it possible that, we have 2 xaml user control page and having 1 code behind xaml.cs file?
相关问题
- Generic Generics in Managed C++
- How to Debug/Register a Permanent WMI Event Which
- 'System.Threading.ThreadAbortException' in
- Bulk update SQL Server C#
- Should I use static function in c# where many call
Start off by creating three files, first the "code-behind" .cs file is created as a simple class:-
Note it has no
InitializeComponent
call.Now create a new
UserControl
then modify its xaml to look like this:-Note the addition the
xmlns:local
alias to point to your app's namespace then the change of theUserControl
tag to the base control we actually want.You would modify the .xaml.cs to this:-
That is all the .xaml.cs needs to contain.
You can then repeat this for
SecondMyCommonUserControl
and so on. Place all the common code in the baseMyCommonUserControl
class.Its a pity MS didn't anticipate this in the first place, adding an empty virtual InitializeComponent method to the underlying
UserControl
and having the .g.i.cs auto-generated codeoverride
the method would have meant that we could dispense with this superflous .xaml.cs file in these cases.