Skip to main content

Microsoft Silverlight

Answered Question Silverlight 2 Beta 2 + blend June preview - Inherit from UserControlRSS Feed

(0)

rceles
rceles

Member

Member

23 points

12 Posts

Silverlight 2 Beta 2 + blend June preview - Inherit from UserControl

Hi, i want to do a second level of hierarchy from usercontrol, but i dont get work blend correctly with this.

Example:

class MyBaseUserControl: UserControl{}

class Page: MyBaseUserControl{} 

i get work vsstudio and compile (i change the page.xaml and page.cs, for begin with MyBaseUserControl and its namespaces and compile and work OK), but in Blend i get, "content" can be set.

For do this objects work, i change to inherit mybaseusercontrol from ContentControl.

 

But i want that designer add GroupStates and VisualStates (as in UserControl).

 

Any idea?

Thanks a Lot!

Roberto. 

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Answered Question

Re: Silverlight 2 Beta 2 + blend June preview - Inherit from UserControl

Hello, first of all, make sure you base Control is code only, or it won't work. Currently Blend doesn't support the inherit scenario. We're investigating the possibility to add the support in a future release. But I can't assure you at this time.

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

rceles
rceles

Member

Member

23 points

12 Posts

Re: Re: Silverlight 2 Beta 2 + blend June preview - Inherit from UserControl

 Hi thanks for your reply.

I currently get work MyCustomUserControl base class in Vs and Blend, doing the next:

class MyCustomUserControl: UserControl{

        public new UIElement Content
        {
            get { return base.Content; }
            set
            {
                base.Content = new ContentControl();
                ((ContentControl)base.Content).Content = value;
            }
        }

8<--------------------------------------------- 

class MyBlendXamlUserControl: MyCustomUserControl{

      public MyBlendXamlUserControl(){

      }

8<---------------------------------------------- 

<local:MyCustomUserControl xmlns:local="...." ...>

</local:MyCustomUserControl>

 

Then Blend and VS Designer Work correctly.

The problem with inherit from usercontrol i see that is "Content" property is protected, not as "ContentControl" that is public. If i inherit from contentcontrol then blend work correctly, but template is not editable (the default xaml code that blend add to the page dont work in this scenario); but if you inherit from usercontrol, if you dont hide the "content" property as "public" the blend say "content property" cant set, and at run time the Xamlparse say the same; but if you hide as public, this in design view work correctly, but XamlParse trhow "Catastrofic Error" that if i do as the code show, assign the ContentProperty (CoreDependencyProperty) as a new ContentControl and then the Content of this as the value, work correctly in Blend and XamlParse at runtime.

 

Thanks! and regards. 

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities