Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Silverlight 2 Beta 2 + blend June preview - Inherit from UserControl
2 replies. Latest Post by rceles on July 18, 2008.
(0)
rceles
Member
23 points
12 Posts
07-16-2008 7:08 PM |
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 L...
All-Star
25052 points
2,747 Posts
07-18-2008 12:10 AM |
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.
07-18-2008 11:23 AM |
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.