Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. interfaces and access modifiers

interfaces and access modifiers

Scheduled Pinned Locked Moved WPF
csharphelpwpfwinformstutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Ed Hill _5_
    wrote on last edited by
    #1

    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.

    P 1 Reply Last reply
    0
    • E Ed Hill _5_

      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.

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      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

      E 1 Reply Last reply
      0
      • P Pete OHanlon

        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

        E Offline
        E Offline
        Ed Hill _5_
        wrote on last edited by
        #3

        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.

        P 1 Reply Last reply
        0
        • E Ed Hill _5_

          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.

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          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

          My blog | My articles | MoXAML PowerToys | Onyx

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups