开发者

How to add custom Controls in Expression Blend?

I have a Form created using Expression Blend. Earlier when I created one in Visual Studio, I could add a custom control using Controls.Add(). An example would be as follows.

Using SriClocks;
//////////////////////Blah blah
public Form1()
{
    InitializeComponent();
    SriClocks.DigitalClockCtrl clk = new DigitalClockCtrl();
    clk.Size = new Size(500, 150);
    clk.Show();
    this.Controls.Add(clk);
    clk.SetDigitalColor = DigitalColor.GreenColor;
}

When I create the form using expression blend, I can't use开发者_如何学运维 the above method to add a control to the form. by

    this.Controls.Add(**)
Can someone please let me know how to achieve this task! Thanks a lot.


Your first code example looks like a Windows.Forms application, but Expression Blend creates WPF applications. Therefore there is no this.Controls-Enumeration. You should add the Control to the Grid (or whatever else container you used), like

Class1.xaml

<Window x:Class="Class1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="About" Height="300" Width="350" ResizeMode="NoResize">
    <Grid x:Name="grid" />
</Window>

Class1.xaml.cs

...
public Class1()
{
    InitializeComponent();
    SriClocks.DigitalClockCtrl clk = new DigitalClockCtrl { Size = new Size(500,150) };
    this.grid.Children.Add(clk);
}
...
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜