I am developping a WPF application in XAML. I am a beginner and I have an issue with my button. I need to set its height as a proportion of its container which is a grid. I saw that the height can be set to a value or to "Auto", but I don't know how to say to my button that his height must be 3/4 of the height of the grid in which it is contained.
Does anybody know how to deal with that ? Is it possible to do that with XAML ?
The objective is that when the grid grows, the button grows with it.
Any help would be appreciate.
Thanks
Here is the code I wrote :
<Window x:Class="WpfAppButtonSize.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfAppButtonSize"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid Height="100" Width="250" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Content="Button 1" FontSize="30" Height="75" Width="150"/>
</Grid>
</Grid>
For the button, instead of Height="75", I would like to say Height=0.75 * Grid Height
If you give your Grid and your Button a name by specifying the
x:Nameattribute, you could set the Button'sHeightin the code behind whenever the Grid's size changes.XAML
MainWindow.xaml.cs
In WPF you could then do this in the code-behind:
while in other .NET technologies, such as Xamarin.Forms or .NET MAUI it would have to look like this: