如何删除stackpanel C#xaml中按钮之间的空格?

时间:2014-08-11 16:45:40

标签: c# xaml button windows-phone

在xaml布局中,按钮之间没有空格。但是,当我在模拟器或设备中测试它时,按钮之间有空格。我怎样才能解决这个问题?

<phone:PhoneApplicationPage
    x:Class="KentKart.Pages.Page1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d"
    shell:SystemTray.IsVisible="True">

    <phone:PhoneApplicationPage.Resources>
        <Style x:Key="SimpleButton" TargetType="Button">
            <Setter Property="Margin" Value=",,,-13"/>
            <Setter Property="Padding" Value="40,5,0,5"/>
            <Setter Property="HorizontalContentAlignment" Value="Left"/>
            <Setter Property="BorderThickness" Value="2"/>
            <Setter Property="BorderBrush" Value="#0079c8"/>
            <Setter Property="HorizontalAlignment" Value="Stretch"/>
            <Setter Property="VerticalAlignment" Value="Stretch"/>
            <Setter Property="Background" Value="White"/>
            <Setter Property="Foreground" Value="#0079c8"/>
        </Style>
    </phone:PhoneApplicationPage.Resources>

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Grid.Background>
            <ImageBrush Stretch="Fill" ImageSource="/Assets/Images.xcassets/Background.imageset/bg@2x.png" AlignmentY="Top" AlignmentX="Center"/>

        </Grid.Background>
        <Grid Background="#0079c8" Height="92" VerticalAlignment="Top">
            <TextBlock Width="auto" x:Name="selectedCityText" Foreground="White"  Text="" RenderTransformOrigin="-0.243,0.771" FontSize="15" Margin="0,10,0,28" />
        </Grid>
        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel Grid.Row="0" Margin="12,17,0,28">
            <Button Content="X" BorderThickness="0" HorizontalAlignment="Left" Margin="367,0,-12,0" VerticalAlignment="Top" Height="64" Width="113" Click="X_Button" RenderTransformOrigin="0.519,0.125"/>
        </StackPanel>
        <StackPanel VerticalAlignment="Top" Margin="0,92,0,0">

            <Button Style="{StaticResource SimpleButton}" Content="deneme"/>
            <Button Style="{StaticResource SimpleButton}" Content="deneme"/>
            <Button Style="{StaticResource SimpleButton}" Content="deneme"/>

        </StackPanel>


        <!--ContentPanel - place additional content here-->
    </Grid>



</phone:PhoneApplicationPage>

1 个答案:

答案 0 :(得分:2)

经过一些调整后,解决方案就是

<Setter Property="Margin" Value="0,-10,0,-10"/>

您需要移除20像素的边距。但是左和右的0是关键的,当你把它们留空时你可以看到默认值是负的(它们伸出框架)。在设计师和设备上呈现的方式似乎有所不同。

因此,可能存在值得报告的潜在错误。