0

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]);
        }
    }
quetzalcoatl
  • 32,194
  • 8
  • 68
  • 107
Noberto Pessôa
  • 125
  • 3
  • 12

1 Answers1

1

Oh, I got it. I've just put System.Windows.Controls.Canvas.SetTop instead only Canvas.SetTop.

What a shame..

Noberto Pessôa
  • 125
  • 3
  • 12
  • 2
    That's probably because you have a method named `Canvas`. Thus just hitting `Canvas.SetTop` you're trying to access `.SetTop` of your `Canvas()` method which doesn't make sense. I bet if you rename `public void Canvas()` to something else, `Canvas.SetTop` would work fine. – Chris Sinclair Jun 21 '13 at 02:02
  • Quite a time has passed since you've found your solution. Please mark your own answer as "accepted" one, so we know that your question/problem is now solved! – quetzalcoatl Jul 11 '13 at 13:10