WPF textbox height equal to parent height minus 50 pixels?

I successfully get a TextBox to resize with the parent border height, but I need the TextBox to actually be 50 pixels smaller in height than the parent border.

Any ideas how to achieve this?

The code I'm using is

<Border VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
     <TextBox x:Name="txtActivityNotes" HorizontalAlignment="Stretch" Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Border}}, Path=ActualHeight}" AcceptsReturn="True" VerticalContentAlignment="Top" TextWrapping="WrapWithOverflow" VerticalScrollBarVisibility="Auto" />
</Border>
+3
source share
3 answers

Can't you set a lower limit of 50?

<TextBox Margin="0,0,0,50" />
+8
source

I tried to follow and it works. add the following to the text box in xaml:

------
VerticalAlignment="Stretch" 
HorizontalAlignment="Stretch" 
Height="{Binding RelativeSource={RelativeSource FindAncestor, *AncestorType*={x:Type *Grid*}}, Path=ActualHeight}"
------

Here AncestorType is a container type containing a text field. In my case, it was the Grid. Also add margin, for example,

  Margin="0,0,0,50"

to keep the distance from the border below.

============

oops , .

+4
+2
source

Source: https://habr.com/ru/post/1722949/


All Articles