开发者

How to create the border of a dynamic canvas in Silverlight?

开发者 https://www.devze.com 2022-12-24 16:10 出处:网络
Hi I am creating a Canvas in code behind like below: Canvas musicPlayerCanvas = new Canvas(); musicPlayerCanvas.Background = new SolidColorBrush(Colors.White);

Hi I am creating a Canvas in code behind like below:

Canvas musicPlayerCanvas = new Canvas();
                    musicPlayerCanvas.Background = new SolidColorBrush(Colors.White);
                    musicPlayerCanvas.Height = 80;
                    musicPlayerCanvas.Width = 1018;
LayoutRoot.Children.Add(musicPlayerCanvas);

musicPlayerCanvas.Children.Add(playingText);
musicPlayerCanvas.Children.Add(albumImage);

Now how can I add border to the canvas from the codebehind.

I tried with creating a Border and assigning a child like below:

Border myBorder = new Border();
                    //Border Proporties



                    Canvas.SetTop(musicPlayerCanvas, 26);
                    Canvas.SetLeft(musicPlayerCanvas, 154);
                    LayoutRoot.Children.Add(musicPlayerCanvas);
                    myBorder.Child = musicPlayerCanvas;

It is not working 开发者_开发问答for me . Any help please.

Thanks, Subhen


You want to add the canvas to the border, like so:

Canvas musicPlayerCanvas = new Canvas();
musicPlayerCanvas.Background = new SolidColorBrush(Colors.Purple);

Border border = new Border();
border.BorderBrush = new SolidColorBrush(Colors.Black);
border.BorderThickness = new Thickness(5);
border.Height = 80;
border.Width = 1018;
border.Child = musicPlayerCanvas;

LayoutRoot.Children.Add(border);

On a side note, when using controls like text boxes and images (which is what I think you might be doing looking at your control names), you might want to use a Grid rather than a Canvas as a container control. Cheers, Phil

0

精彩评论

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

关注公众号