how to prevent myControl.g.cs from overwriting with wrong base class

Posted by Jonny Cundall on Stack Overflow See other posts from Stack Overflow or by Jonny Cundall
Published on 2010-05-18T22:25:40Z Indexed on 2010/05/18 22:30 UTC
Read the original article Hit count: 206

Filed under:

I've got two custom cursors for my app, MyCursor and MyOtherCursor, both of which were designed in xaml, and I added some behaviour in the xaml.cs for each of them. This behaviour was the same for both so I had them inherit from a base class to reduce code duplication.

public partial class myCursor: CursorBase
{
    public InterchangeCursor()
    {
        InitializeComponent();
    }
}

public class CursorBase : UserControl
{
    public virtual void MoveTo(Point pt)
    {
        this.SetValue(Canvas.LeftProperty, pt.X);
        this.SetValue(Canvas.TopProperty, pt.Y);
    }
}

my problem is that if I change something in the xaml for MyCursor, the MyCursor.g.cs file is regenerated, and instead of inheriting from CursorBase, the partial class in the g.cs inherits from System.Windows.Controls.UserControl. Since the other side of the partial class in the xaml.cs file still inherits CursorBase, a build error occurs. I'm finding it annoying fixing the g.cs file each time. Does anyone know how to prevent this happening?

© Stack Overflow or respective owner

Related posts about Silverlight