我已经使用过Canvas.SetLeft
或Canvas.SetTop
以前使用过,但现在出现错误。我在窗口网格内的 WrapPanel 中有 Canvas:
<Grid>
<WrapPanel>
</WrapPabel>
</Grid>
当窗口被加载时,它被称为一个方法Canvas()
,在其中我实现了一些画布和标签。当我尝试将标签放置在其画布 ( Canvas.SetTop(lab, 10)
) 内时,我收到此错误:
Canvas() is a 'method' , which is not valid in the given context.
我是编程初学者,我不知道为什么会发生这种情况以及该怎么做......
public void Canvas()
{
Canvas[] cans = new Canvas[5];
Label[] lb = new Label[5];
for (int i = 0; i < 5; i++)
{
lb[i] = new Label();
cans[i] = new Canvas();
cans[i].Height = 132;
cans[i].Width = 283;
cans[i].Background = new SolidColorBrush(Colors.Gray);
cans[i].Margin = new System.Windows.Thickness(5);
lb[i].Content = "BOSTA";
Canvas.SetTop(lb[i], 20); //problematic line
cans[i].Children.Add(lb[i]);
wp.Children.Add(cans[i]);
}
}