I've already used Canvas.SetLeft
or Canvas.SetTop
before, but now I'm getting an error.
I have Canvas inside a WrapPanel which is inside the Grid of the Window:
<Grid>
<WrapPanel>
</WrapPabel>
</Grid>
When the window is loaded, it's called a method Canvas()
and inside it I implement some canvas and labels inside them. When I try to position the labels inside its canvas (Canvas.SetTop(lab, 10)
) I get this error:
Canvas() is a 'method' , which is not valid in the given context.
I'm a beginner with programming and I don't know why this happens and what to do...
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]);
}
}