question

JerryM-2071 avatar image
0 Votes"
JerryM-2071 asked JerryM-2071 answered

Binding to grid size from UserControl

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


windows-wpf
pict-1.jpg (189.0 KiB)
pict-2.jpg (405.4 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Viorel-1 avatar image
1 Vote"
Viorel-1 answered

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.




5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DaisyTian-1203 avatar image
1 Vote"
DaisyTian-1203 answered

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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JerryM-2071 avatar image
0 Votes"
JerryM-2071 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.