绝对位置元素WPF

时间:2013-04-03 09:59:52

标签: c# .net wpf silverlight xaml

我想在对话框的右上角放置一个十字按钮,而不会影响对话框其余部分的流程,这对于CSS来说似乎相当困难?

目前,该内容与右侧的内容大约相差20px,因为它仍然在第0列和第1列占据该空间。理想情况下,所有内容都在StackPanel内,关闭按钮位于右上方。如果失败,我猜可能会使内容跨越两列?我该如何解决这个问题?

这是我目前的XAML:

<Grid Margin="10">
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition/>
    </Grid.RowDefinitions>

    <StackPanel Grid.Row="0">
        <TextBlock x:Name="UI_DialogTitle" Style="{StaticResource i2_TitleTextBlock}" Text="{TemplateBinding DialogTitle}" Visibility="{TemplateBinding DialogTitleVisibility}" Margin="0,0,0,10"/>
        <ContentPresenter x:Name="TheContentPresenter"/>
    </StackPanel>

    <Button x:Name="UI_CloseDialog" Style="{StaticResource i2_CloseDialogButton}" Visibility="{TemplateBinding CloseButtonVisibility}" Grid.Column="1" Grid.Row="0"/>
</Grid>     

2 个答案:

答案 0 :(得分:1)

原来我需要ColumnSpan属性 - 现在一切正常!

<Grid Margin="10">
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition/>
    </Grid.RowDefinitions>

    <StackPanel Grid.Row="0" Grid.ColumnSpan="2">
        <TextBlock x:Name="UI_DialogTitle" Style="{StaticResource i2_TitleTextBlock}" Text="{TemplateBinding DialogTitle}" Visibility="{TemplateBinding DialogTitleVisibility}" Margin="0,0,0,10"/>
        <ContentPresenter x:Name="TheContentPresenter"/>
    </StackPanel>

    <Button x:Name="UI_CloseDialog" Style="{StaticResource i2_CloseDialogButton}" Visibility="{TemplateBinding CloseButtonVisibility}" Grid.Column="1" Grid.Row="0"/>
</Grid>  

答案 1 :(得分:0)

我做了类似的事情。检查btnClose和屏幕截图。

<Grid x:Name="LayoutRoot" Margin="2">
        <Border x:Name="PopupBorder" BorderBrush="SlateGray" BorderThickness="1.5" CornerRadius="12" Visibility="Visible" Opacity="20" Margin="0,0,0,0">
            <Border.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FF000000"/>
                    <GradientStop Color="#CC4895DE" Offset="0.844"/>
                    <GradientStop Color="#FF346592" Offset="0.393"/>
                    <GradientStop Color="#FFFFFFFF" Offset="1"/>
                </LinearGradientBrush>
            </Border.Background>
            <TextBox Height="26" Style="{StaticResource TextBoxStyle}" Margin="0,0,30,220" Name="txtQuotationNumber" Width="332" />

        </Border>
        **<Button Margin="0,4,4,0" Click="OKButton_Click" Cursor="Hand" x:Name="btnClose" Style="{StaticResource CloseStyleX}" VerticalAlignment="Top" ToolTipService.ToolTip="Close Popup"/>**

        -- Datagrid here
        -- COMBOBOX HERE

        <TextBox Height="26" Name="txtValue" IsTabStop="True" VerticalAlignment="Top" Margin="178,10,500,0"></TextBox>
        <Button Content="Search" Click="btnSearch_Click" Style="{StaticResource ButtonStyle}" Height="26" HorizontalAlignment="Right" Margin="0,10,37,0" Name="btnSearch" VerticalAlignment="Top" Width="104" />
    </Grid>

enter image description here