保证金相对于元素

时间:2013-06-05 20:34:14

标签: c# xaml windows-phone-8 alignment

如何将相对位置不同的元素下方的元素对齐?

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

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

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>

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

0 个答案:

没有答案