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. WPF user controls

WPF user controls

Scheduled Pinned Locked Moved WPF
csharpwpfwinformsoophelp
4 Posts 3 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.
  • K Offline
    K Offline
    koleraba
    wrote on last edited by
    #1

    Hi! I need to implement a few UserControls in WPF. Since they all have some common functionality I want to create a base class from which they would all derive. The problem is that UserControl has to extend the UserControl class and there is no multiple inheritance in c#. Does anybody know a good way around this problem? Every advice will be appreciated! Uros Bregar

    C 1 Reply Last reply
    0
    • K koleraba

      Hi! I need to implement a few UserControls in WPF. Since they all have some common functionality I want to create a base class from which they would all derive. The problem is that UserControl has to extend the UserControl class and there is no multiple inheritance in c#. Does anybody know a good way around this problem? Every advice will be appreciated! Uros Bregar

      C Offline
      C Offline
      ColinM123
      wrote on last edited by
      #2

      You just use an inheritance chain Create your base class inheriting from the UserControl class MyBaseControl : UserControl Then your control inherits from your base class, simple (If I understood the question correctly :) ActualControl : MyBaseControl

      K 1 Reply Last reply
      0
      • C ColinM123

        You just use an inheritance chain Create your base class inheriting from the UserControl class MyBaseControl : UserControl Then your control inherits from your base class, simple (If I understood the question correctly :) ActualControl : MyBaseControl

        K Offline
        K Offline
        koleraba
        wrote on last edited by
        #3

        I guess i didn't explain my problem well enough. When you create a user control in visual studio, you actually get three files. .cs, .xaml and .g.cs(when using xaml and c#). When you change the base class of the partial class defined in .cs file, you have to do the same for the class defined in the .g.cs file, since partial classes have to have the same base class. The problem is that the .g.cs file is auto-generated by VS and gets changed every time the content of the xaml file is re-compiled. Uros Bregar

        M 1 Reply Last reply
        0
        • K koleraba

          I guess i didn't explain my problem well enough. When you create a user control in visual studio, you actually get three files. .cs, .xaml and .g.cs(when using xaml and c#). When you change the base class of the partial class defined in .cs file, you have to do the same for the class defined in the .g.cs file, since partial classes have to have the same base class. The problem is that the .g.cs file is auto-generated by VS and gets changed every time the content of the xaml file is re-compiled. Uros Bregar

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          Is this what you're looking for?

          namespace MyNamespace
          {
          public partial class MyUserControlBase : UserControl
          {
          public MyUserControlBase()
          {
          }
          }

          public partial class MyUserControl : MyUserControlBase
          {
              public MyUserControl()
              {
                  InitializeComponent();
              }
          }
          

          }

          <local:MyUserControlBase x:Class="MyNamespace.MyUserControl"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:local="clr-namespace:MyNamespace"
          Height="300" Width="300">
          <Grid>
          </Grid>
          </local:MyUserControlBase>

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          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