0

如何将一个元素相对于高度未知的不同元素下方对齐?

我尝试的是创建一个转换器来获取不同元素的边距并在它们之间添加所需的空间,但我不知道如何添加不同元素的高度以真正实现我想要的。

这是我正在谈论的转换器:

public class MargConv : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (targetType.Equals(typeof(Thickness)))
        {
            Thickness thick = (Thickness)value;
            thick.Top += 51;
            thick.Left = System.Convert.ToInt32(parameter) == 1 ? 22 : 151;

            return thick;
        }

        return value;
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        Thickness thick = (Thickness)value;
        thick.Top -= 51;
        return thick;
    }
}

编辑:

我正在谈论的 XAML:

        <ScrollViewer HorizontalAlignment="Left" Height="699" VerticalAlignment="Top" Width="456">
            <Grid HorizontalAlignment="Left" Height="699" VerticalAlignment="Top" Width="456">
                <TextBlock Name="areat" HorizontalAlignment="Left" Margin="22,33,0,0" TextWrapping="Wrap" Text="איזור מגורים:" VerticalAlignment="Top"/>
                <TextBlock Name="area" HorizontalAlignment="Left" Margin="151,37,0,0" TextWrapping="Wrap" Text="{Binding Area}" VerticalAlignment="Top" FontSize="20"/>
                <TextBlock Margin="{Binding ElementName=area, Path=Margin, Converter={StaticResource margconv}, ConverterParameter=1}" HorizontalAlignment="Left" TextWrapping="Wrap" Text="תיאור משרה:" />
                <TextBlock Name="content"  HorizontalAlignment="Left" Margin="{Binding ElementName=area, Path=Margin, Converter={StaticResource margconv}, ConverterParameter=0}" TextWrapping="Wrap" Text="{Binding Content}" VerticalAlignment="Top" FontSize="20" />
                <TextBlock HorizontalAlignment="Left" Margin="{Binding ElementName=content, Path=Margin, Converter={StaticResource margconv}, ConverterParameter=1}" TextWrapping="Wrap" Text="תאריך עדכון:"/>
                <TextBlock Name="date" HorizontalAlignment="Left" Margin="{Binding ElementName=content, Path=Margin, Converter={StaticResource margconv}, ConverterParameter=0}" TextWrapping="Wrap" Text="{Binding Date}" VerticalAlignment="Top" FontSize="20"/>

                <TextBlock HorizontalAlignment="Left" Margin="{Binding ElementName=date, Path=Margin, Converter={StaticResource margconv}, ConverterParameter=1}" TextWrapping="Wrap" Text="דוא&quot;ל לחזרה:" VerticalAlignment="Top"/>
                <TextBox Name="email" HorizontalAlignment="Left" Height="72" Margin="{Binding ElementName=date, Path=Margin, Converter={StaticResource margconv}, ConverterParameter=0}" TextWrapping="Wrap" Text="{Binding RetEmail}" VerticalAlignment="Top" Width="303"/>
                <Button Content="שלח קו&quot;ח" HorizontalAlignment="Left" Margin="{Binding ElementName=email, Path=Margin, Converter={StaticResource margconv}, ConverterParameter=1}" VerticalAlignment="Top" Click="SendResume"/>
            </Grid>
        </ScrollViewer>

我想在其他文本块下方对齐文本块,但不知道它们的高度(它们的文本是从某些数据源获取的,因此它不是静态的 => 高度正在改变)。

4

0 回答 0