How to resize control according to another control ? (WPF)

Mangesh

I have a Label & a Border(the line) which I want to show as follows

enter image description here

The problem is client's name can be of any size and then it overlaps on the line. Is there any way to relate the line to the size of the label?

Note: Both components are in the same cell of Grid.

Peter

That's what Grid is for. You can put a grid inside the cell of a grid, or you could use the outer grid in combination with ColumnSpan:

<Grid MaxWidth="240">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>

    <Label Content="Client Name" Grid.Column="0" />
    <Border Grid.Column="1" ... />
</Grid>

The first column gets as much space as it needs, the second as much as it can get (which can be more, or less, than it needs). The MaxWidth which I put on the grid is optional. it makes sure the Client Name is cut off if it exceeds a certain length. There are several other ways of doing this, but I find Grid is the most flexible and the easiest to maintain, despite requiring more characters to write.

The approach given by kidshaw:

<DockPanel LastChildFill="True">
    <Label Content="Client Name" DockPanel.Dock="Left" />
    <Border ... />
</DockPanel>

The next one will draw the label on top of the border, but requires knowing the background color, which won't work if the background is a gradient or image:

<Border ... />
<Label HorizontalAlignment="Left" Content="Client Name" Background="White" />

Here's a different question that, although the question asked is quite different, has the same answers: How to get StackPanel's children to fill maximum space downward?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to Bind to Another Control Property in WPF

From Dev

How to adjust control width and height according to windows width and height in WPF

From Dev

How do I resize a WPF control inside a CWnd?

From Dev

How to Resize an image on an Image Control?

From Dev

wpf how to control storyboard

From Dev

Updating NumericUpDown value according to another NumericUpDown control

From Dev

How can I pass application control to another WPF window?

From Dev

How to Pass a value from One User Control to another in WPF.

From Dev

How can I pass application control to another WPF window?

From Dev

How to get a control that is underneath another control?

From Dev

Custom Control - how to encapsulate aggregation in another control

From Dev

Getting a WPF control to trigger and set another control's itemssource

From Dev

WPF: Custom control property was already registered by another custom control error

From Dev

Detect Mouseover on some inner control inside another control in wpf

From Dev

How to clear WebBrowser control in WPF

From Dev

How to take a screenshot of a WPF control?

From Dev

How to extend WPF Path control

From Dev

How to limit focus to a Control in WPF

From Dev

WPF How to refresh a user control

From Dev

How to replace / overwrite a Control in WPF

From Dev

How to take a screenshot of a WPF control?

From Dev

How to translate a control smoothly in wpf?

From Dev

WPF - Binding Listview Grid cell to another control

From Dev

How to Resize ListView control when resizing window

From Dev

How to Resize ListView control when resizing window

From Dev

How to resize textLabel in segmented control in Swift?

From Dev

Center a control in another control

From Dev

How to bind an object from one window to another control in another window in wpf? (c#)

From Dev

Resize overlay control with window resize

Related Related

  1. 1

    How to Bind to Another Control Property in WPF

  2. 2

    How to adjust control width and height according to windows width and height in WPF

  3. 3

    How do I resize a WPF control inside a CWnd?

  4. 4

    How to Resize an image on an Image Control?

  5. 5

    wpf how to control storyboard

  6. 6

    Updating NumericUpDown value according to another NumericUpDown control

  7. 7

    How can I pass application control to another WPF window?

  8. 8

    How to Pass a value from One User Control to another in WPF.

  9. 9

    How can I pass application control to another WPF window?

  10. 10

    How to get a control that is underneath another control?

  11. 11

    Custom Control - how to encapsulate aggregation in another control

  12. 12

    Getting a WPF control to trigger and set another control's itemssource

  13. 13

    WPF: Custom control property was already registered by another custom control error

  14. 14

    Detect Mouseover on some inner control inside another control in wpf

  15. 15

    How to clear WebBrowser control in WPF

  16. 16

    How to take a screenshot of a WPF control?

  17. 17

    How to extend WPF Path control

  18. 18

    How to limit focus to a Control in WPF

  19. 19

    WPF How to refresh a user control

  20. 20

    How to replace / overwrite a Control in WPF

  21. 21

    How to take a screenshot of a WPF control?

  22. 22

    How to translate a control smoothly in wpf?

  23. 23

    WPF - Binding Listview Grid cell to another control

  24. 24

    How to Resize ListView control when resizing window

  25. 25

    How to Resize ListView control when resizing window

  26. 26

    How to resize textLabel in segmented control in Swift?

  27. 27

    Center a control in another control

  28. 28

    How to bind an object from one window to another control in another window in wpf? (c#)

  29. 29

    Resize overlay control with window resize

HotTag

Archive