locked
Location in WPF RRS feed

  • Question

  • I have in C# . 

     matCell[i, j].Height = (double.Parse((Logic.HEIGHTMISH - 2).ToString()));
     matCell[i, j].Width = (double.Parse((Logic.WIDTHMISH - 2).ToString()));
     matCell[i, j].Location = new Point(j * Logic.WIDTHMISH, i * Logic.HEIGHTMISH);
    I want to translate it in WPF

    WPF knows Heigt and WIdth but not Location. How can I write yhe Location in WPF ?


    Monday, February 23, 2015 2:13 PM

Answers

  • You set the Left and Top properties of the Window:

        public MainWindow() {
          InitializeComponent();
    
    this.Top = 100;
    this.Left = 100;
    }
    //if matCell contains Window objects: 
    matCell[i, j].Left = j * Logic.WIDTHMISH;
     matCell[i, j].Top = i * Logic.HEIGHTMISH;

    Please remember to mark helpful posts as answer to close your threads.

    Monday, February 23, 2015 2:23 PM
  • I have in C# . 

     matCell[i, j].Height = (double.Parse((Logic.HEIGHTMISH - 2).ToString()));
     matCell[i, j].Width = (double.Parse((Logic.WIDTHMISH - 2).ToString()));
     matCell[i, j].Location = new Point(j * Logic.WIDTHMISH, i * Logic.HEIGHTMISH);
    I want to translate it in WPF

    WPF knows Heigt and WIdth but not Location. How can I write yhe Location in WPF ?


    To find position of a  control:

    Point relativePoint = myVisual.TransformToAncestor(rootVisual)
                              .Transform(new Point(0, 0));

    Where rootvisual is whichever visual you want the position relative to. Like this for the window.

    myVisual is your control.

    You get a point which has x and y co-ordinates.

    https://msdn.microsoft.com/en-us/library/system.windows.point%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396


    I used to be a points hound.
    But I'm alright nooooooooooooooooooooooooooooOOOOOWWWW !

    Monday, February 23, 2015 2:34 PM

All replies

  • You set the Left and Top properties of the Window:

        public MainWindow() {
          InitializeComponent();
    
    this.Top = 100;
    this.Left = 100;
    }
    //if matCell contains Window objects: 
    matCell[i, j].Left = j * Logic.WIDTHMISH;
     matCell[i, j].Top = i * Logic.HEIGHTMISH;

    Please remember to mark helpful posts as answer to close your threads.

    Monday, February 23, 2015 2:23 PM
  • I have in C# . 

     matCell[i, j].Height = (double.Parse((Logic.HEIGHTMISH - 2).ToString()));
     matCell[i, j].Width = (double.Parse((Logic.WIDTHMISH - 2).ToString()));
     matCell[i, j].Location = new Point(j * Logic.WIDTHMISH, i * Logic.HEIGHTMISH);
    I want to translate it in WPF

    WPF knows Heigt and WIdth but not Location. How can I write yhe Location in WPF ?


    To find position of a  control:

    Point relativePoint = myVisual.TransformToAncestor(rootVisual)
                              .Transform(new Point(0, 0));

    Where rootvisual is whichever visual you want the position relative to. Like this for the window.

    myVisual is your control.

    You get a point which has x and y co-ordinates.

    https://msdn.microsoft.com/en-us/library/system.windows.point%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396


    I used to be a points hound.
    But I'm alright nooooooooooooooooooooooooooooOOOOOWWWW !

    Monday, February 23, 2015 2:34 PM