Binding to grid size from UserControl

JerryM 1,131 Reputation points
2021-05-30T08:15:08.16+00:00

Hello,

I have a TabControl and a TabItem inside it. Inside the TamItem is a Grid named "xml_grid_004" and inside the Grid "xml_grid_004" is a UserControl - see the PICTURE-1 below.

So, how can I obtain the width and height of "xml_grid_004" in UserControl using Binding ? If I use classic binding to Width and Height to parent of the UserControl (it is, indeed, the "xml_grid_004") the UserControl Width and Height is equal to Zero at design time - see the PICTURE-2 and I do not see the UserControl. Complette source code is here:
https://drive.google.com/file/d/16mYZWndd7nrswWn9W8yf5XU8pPRoqhrb/view?usp=sharing

How can I transfer the "xml_grid_004" Width and Height to my UserControl ???? to be visible in VisualDesigner at design time ? Is it possible ?

PICTURE-1:
100726-pict-1.jpg

PICTURE-2:
100727-pict-2.jpg

Developer technologies Windows Presentation Foundation
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.6K Reputation points
    2021-05-30T08:45:31.987+00:00

    I think that if you remove the Width, Height, Margin, VerticalAlignment, HorizontalAlignment attributes of user control, scroll viewer and grids, then the user control and scroll viewer will occupy the whole area of tab item automatically.

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. DaisyTian-1203 11,646 Reputation points
    2021-05-31T02:53:38.95+00:00

    It is impossible to transfer xml_grid_004 Width and Height to UserControl1 to be visible in VisualDesigner at design time with binding other windows's elements properties value.
    Reason 1: The Visual Studio can't find the xml_grid_004 at design time , xml_grid_004 is in MainWindow. There is no info to tell UserControl1 that xml_grid_004 is in MainWindow, so UserControl1 can't find xml_grid_004.
    Reason 2: ActualWidth/ActualHeight gets the rendered width/height of this element. The element should be rendered, ActualWidth and ActualHeight are not rendered at design time.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

  2. JerryM 1,131 Reputation points
    2021-05-31T18:12:18.99+00:00

    hm I am very sad and frightened ... as usually ... if MS things are concerned..
    on the other hands .. both replies seems to be ok ..

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.