开发者

Create Silverlight custom control with code only (no xaml)

开发者 https://www.devze.com 2023-01-26 21:28 出处:网络
I would like to create a Silverlight custom control using C# only, without any xaml. Here is my work so far (stripped down to the bare minimum for the question):

I would like to create a Silverlight custom control using C# only, without any xaml.

Here is my work so far (stripped down to the bare minimum for the question):

I tried to inherit User control as follows:

public class myControl: UserControl
{
    // class code
}

And adding it to the LayoutRoot:

myControl control = new myControl();
LayoutRoot.Children.Add(control);

The control is added, but its invisible!!

How can i make it visible ? Is there something i missed ?

edit: The only visual eleme开发者_开发技巧nt in my contorl is a grid with an image background


Your Usercontrol will be empty and have no visual effect until you give it a child control via it's Content property.


Well unless you put a template in place or add elements in code, UserControl is empty.

Maybe you could try inheriting from an existing control which has a template, like Button, etc and change that in code?

0

精彩评论

暂无评论...
验证码 换一张
取 消