Skip to main content

Microsoft Silverlight

Weird problem with designer files and custom user controlsRSS Feed

(0)

piratepops
piratepops

Member

Member

124 points

33 Posts

Weird problem with designer files and custom user controls

This really isn't so much a PROBLEM as an irritation - was wondering if anyone had a fix for it other than just putting up with it.  Here is the situation:

 I'm working on a pretty large Silverlight LOB application.  I created a component as a XAML with its own code-behind, let's call it MyControl.xaml.  This was added to the project, which we'll call MyProject.  Also in MyProject is my main page, which we'll call MainPage.xaml.  I add MyControl to MainPage by doing the following:

1)  I add a reference to it at the top of the xaml with:

<UserControl x:Class="MyProject.MainPage"
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" 
    xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:MyProject" >

 

2)  Futher down in the code of MainPage.xaml, I use the control with:

<local:MyControl x:name="InstanceOfMyControl"></local:MyControl>

 

At first, it works like a charm.  But then I start getting error messages, which sometimes prevent compilation that say that MyControl is not part of MyProject.  The error is in the file MainPage.g.vb, and the lines of code look like this:

 Friend WithEvents InstanceOfMyControl As MyProject.MyControl

and

Me.InstanceOfMyControl = CType(Me.FindName("InstanceOfMyControl"), MyProject.InstanceOfMyControl)

 Now - when I debug this, the recommended change is to change the lines of code to this:

 

 Friend WithEvents InstanceOfMyControl As MyControl

and

Me.InstanceOfMyControl = CType(Me.FindName("InstanceOfMyControl"), InstanceOfMyControl)

 

This removes the error, everything compiles and runs fine.  But then after a few minutes, I guess when the .g.vb file is 're-generated', the code goes back to the way it was, and the errors come back.  Sometimes they go away when I compile without me having to fix, but other times the app won't compile at all until I manually fix the .g.vb file.

 

Any suggestions?

Thanks in advance,

Pops

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities