控制不正确

时间:2014-01-21 14:33:59

标签: wpf xaml

我想像这张照片一样控制位置 enter image description here

我需要将下一个和上一个按钮设为pic 1,但我得到以下内容,但无法解决此问题。 enter image description here

请指导,XAML代码:

<StackPanel Grid.Row="4">
        <Grid x:Name="GridNavigation">
            <Button x:Name="Gridprevbutton" Content="Previous" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="121,0,0,0"></Button>
            <Button x:Name="Gridnextbutton" Content="Next" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="231 , 0, 0, 0"></Button>
            <Button x:Name="Gridendexambuton" Content="End Exam" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,0,5,0"></Button>
        </Grid>
        <TextBlock HorizontalAlignment="Right" Margin="0,5,10,0" TextDecorations="Underline">Contact Support</TextBlock>
</StackPanel>

(编辑)我最后在@davisoa建议之后这样做了。并使它工作。

背后的代码

private void SetNavigation()
{
    var img = Common.AddImageToContainer("images/lowerleftblock.png", GridNavigation, Common.ToDictionaryTLST("top", "left", "none"));
        img.Margin = new Thickness(0,16,0,0);
        Panel.SetZIndex(img, -1);       
}

2 个答案:

答案 0 :(得分:1)

在我看来,上面没有显示的GridStackPanel中的第一个Grid.Row="4")限制了“下一个”和“上一个”按钮的高度。

此示例XAML显示问题块低于按钮。

  • Image更改为StackPanel Label,因为我没有您的图片
  • VerticalAlignment更改为Bottom,以确保其浮动在Grid
  • 的底部
  • Grid一个固定的Height以确保垂直布局正确。你可能不想这样做

<StackPanel Grid.Row="4">
    <Grid x:Name="GridNavigation" Margin="0,0,0,0" Height="75">
        <StackPanel x:Name="Lowerleftblock" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="0,0,0,0" Background="Green">
          <Label>Question: 1 of 27</Label>
        </StackPanel>
        <Button x:Name="Gridprevbutton" Content="Previous" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="121,0,0,0"></Button>
        <Button x:Name="Gridnextbutton" Content="Next" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="231 , 0, 0, 0"></Button>
        <Button x:Name="Gridendexambuton" Content="End Exam" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,0,5,0"></Button>
    </Grid>
    <TextBlock HorizontalAlignment="Right" Margin="0,5,10,0" TextDecorations="Underline">Contact Support</TextBlock>
</StackPanel>

答案 1 :(得分:1)

为您的图像提供最高限度,以便将其降低。 E.g。

<Image x:Name="Lowerleftblock" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0,20,0,0"></Image>