interfaces and access modifiers
-
I'm looking to inherit from some standard WPF controls, including windows, buttons and a few others. I wish to add some functionality to them that will be common between several controls. My plan was to create an interface for the common functionality, and implement this interface on the required controls. The problem i am getting is that i cannot specify an access modifier on the interface implementations so that they are made available as designer editable properties. For example i created an interface as follows:
public interface iSecurityControled
{
SecuritySettings.ProgramAreas ProgramArea { get; set; }
SecuritySettings.DisabledActions DisabledAction { get; set; }
}public class SecuritySettings { public enum ProgramAreas { None, Client, Development, Block, Accounts } public enum DisabledActions { None, Hide, Disable } }
I then created a class inheriting from the WPF window class and implemented the above interface
public class Form:System.Windows.Window, Interfaces.iSecurityControled
{
#region iSecurityControled Members
private SecuritySettings.ProgramAreas _ProgramArea = SecuritySettings.ProgramAreas.None;
SecuritySettings.ProgramAreas iSecurityControled.ProgramArea
{
get
{
return _ProgramArea;
}
set
{
_ProgramArea = value;
}
}
private SecuritySettings.DisabledActions _DisabledAction = SecuritySettings.DisabledActions.None;
SecuritySettings.DisabledActions iSecurityControled.DisabledAction
{
get
{
return _DisabledAction;
}
set
{
_DisabledAction = value;
}
}
public int MyProperty { get; set; }
#endregion
}My problem is that if i add the public modifier to the properties i get the following error message: The modifier 'public' is not valid for this item. I have tried to add the public modifier to the interface declaration and get the same error. This means that the property is not visible in the designer, however the MyProperty is. To sanity check my thinking i have re done this code as a standard winforms project and it works just as i want it to.
-
I'm looking to inherit from some standard WPF controls, including windows, buttons and a few others. I wish to add some functionality to them that will be common between several controls. My plan was to create an interface for the common functionality, and implement this interface on the required controls. The problem i am getting is that i cannot specify an access modifier on the interface implementations so that they are made available as designer editable properties. For example i created an interface as follows:
public interface iSecurityControled
{
SecuritySettings.ProgramAreas ProgramArea { get; set; }
SecuritySettings.DisabledActions DisabledAction { get; set; }
}public class SecuritySettings { public enum ProgramAreas { None, Client, Development, Block, Accounts } public enum DisabledActions { None, Hide, Disable } }
I then created a class inheriting from the WPF window class and implemented the above interface
public class Form:System.Windows.Window, Interfaces.iSecurityControled
{
#region iSecurityControled Members
private SecuritySettings.ProgramAreas _ProgramArea = SecuritySettings.ProgramAreas.None;
SecuritySettings.ProgramAreas iSecurityControled.ProgramArea
{
get
{
return _ProgramArea;
}
set
{
_ProgramArea = value;
}
}
private SecuritySettings.DisabledActions _DisabledAction = SecuritySettings.DisabledActions.None;
SecuritySettings.DisabledActions iSecurityControled.DisabledAction
{
get
{
return _DisabledAction;
}
set
{
_DisabledAction = value;
}
}
public int MyProperty { get; set; }
#endregion
}My problem is that if i add the public modifier to the properties i get the following error message: The modifier 'public' is not valid for this item. I have tried to add the public modifier to the interface declaration and get the same error. This means that the property is not visible in the designer, however the MyProperty is. To sanity check my thinking i have re done this code as a standard winforms project and it works just as i want it to.
Change
SecuritySettings.DisabledActions iSecurityControled.DisabledAction {
get { return _DisabledAction; }
set { _DisabledAction = value; }
}to
public SecuritySettings.DisabledActions DisabledAction {
get { return _DisabledAction; }
set { _DisabledAction = value; }
}You need to do the same for the other property as well. Basically, you've supplied an explicit interface definition there - when an implicit one will suit your needs.
I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be
My blog | My articles | MoXAML PowerToys | Onyx
modified on Wednesday, August 25, 2010 5:54 AM
-
Change
SecuritySettings.DisabledActions iSecurityControled.DisabledAction {
get { return _DisabledAction; }
set { _DisabledAction = value; }
}to
public SecuritySettings.DisabledActions DisabledAction {
get { return _DisabledAction; }
set { _DisabledAction = value; }
}You need to do the same for the other property as well. Basically, you've supplied an explicit interface definition there - when an implicit one will suit your needs.
I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be
My blog | My articles | MoXAML PowerToys | Onyx
modified on Wednesday, August 25, 2010 5:54 AM
thanks for the quick and helpful response. Your solution worked a treat. I guess as WPF is new to me i was assuming it was to blame for something that was just a simple mistake of mine.
-
thanks for the quick and helpful response. Your solution worked a treat. I guess as WPF is new to me i was assuming it was to blame for something that was just a simple mistake of mine.
Don't worry about it - we all started off fearing WPF; soon the love comes.
I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be