0

I want to make my own control, inheriting from GroupBox.

Ive followed instructions in here, and that's the result of the implementation:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GeneralUserControls
{
    public partial class MyGroupBox : GroupBox
    {
        public MyGroupBox ()
        {
            InitializeComponent();
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);
        }
    }
}

But when I try to use it this way:

<Window [...]
   xmlns:guc="clr-namespace:GeneralUserControls;assembly=GeneralUserControls" >
   [...
<guc:MyGroupBox Header="Etiquette :" Width="70" Height="70">
   <Grid>
      [...]
   </Grid>
</guc:MyGroupBox>

It seems to not consider it as a groupbox! Here are the errors:

Error   1   The property 'Header' was not found in type 'MyGroupBox'.
Error   2   The type 'MyGroupBox' does not support direct content.
Error   3   Cannot add content to an object of type "MyGroupBox".
Error   9   Cannot add content to object of type 'GeneralUserControls.MyGroupBox'.

Any idea?

1 Answer 1

1

You try to mix WPF with WinForms. I see the namespace using System.Windows.Forms; You need to make a WPF custom control, or if you really want a WindowsForms control, you need to wrap it in a WindowsFormsHost control.

The namespace of the GroupBox in WPF is System.Windows.Controls. According to the link you provided, I think you read the wrong tutorial.
You could read for example this: http://wpftutorial.net/HowToCreateACustomControl.html

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.