I have added two windows to a Silverlight 5 application project: FooWindowBase
and SomeFooWindow
. The latter is a sub-class of the former. Both contain a default constructor calling InitializeComponent
, and apparently Visual Studio or the compiler autogenerates that method. This leads to the following compiler warning in the derived class SomeFooWindow
that…
"sub
InitializeComponent
shadows an overloadable member declared in the base classFooWindowBase
. If you want to overload the base method, this method must be declaredOverloads
."
Since InitializeComponent
was autogenerated in both cases, there seems to be no way for me to add a Shadows
over Overloads
specifier.
Is there any way to prevent, or get rid of, this compiler warning without editing the autogenerated code?
FooWindowBase
:
XAML:
<c:ChildWindow x:Class="FooNamespace.FooWindowBase" xmlns:c="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" …> … </c:ChildWindow>
Code:
Imports System.Windows.Controls Partial MustInherit Class FooWindowBase : Inherits ChildWindow Public Sub New() InitializeComponent() End Sub … End Class
SomeFooWindow:
XAML:
<l:FooWindowBase x:Class="FooNamespace.SomeFooWindow" xmlns:l="clr-namespace:FooNamespace;assembly=Foo" …> … </l:FooWindowBase>
Code:
Partial Class SomeFooWindow : Inherits FooWindowBase Public Sub New() InitializeComponent() End Sub … End Class
I'll post the workaround I have ended up using for others who are facing the same problem.
One posted answer to this question asked on Code Project mentions that:
and the solution would be to:
The exact same words are mentioned on this Microsoft Knowledge Base article, btw. So basically, the compiler warning cannot be gotten rid of because that inheritance scenario I've posted simply isn't supported.
I ended up doing the following:
SomeFooWindow
into aUserControl
calledSomeFooControl
;FooWindowBase
toFooWindow
and removed theMustInherit
modifier;ContentPresenter
control toFooWindow
;instead of instantiating the previous
SomeFooWindow
, instantiated aFooWindow
and set theContentPresenter
's content to an instance of aSomeFooControl
: