列表框中的Xaml文本块对齐方式

时间:2014-11-05 08:55:28

标签: c# wpf xaml windows-phone-8 listbox

我正在开发一个Windows手机应用程序,我想在列表框中显示六个文本块,但问题是所有6个值都相互粘贴。我想在它们之间留出一些空间,以便它们在显示时看起来更好。例如,他们目前的样子是

Date|time|floor|zone|latitude|longtitude我希望它们看起来像

Date | Time | floor | zone | latitude | longtitude

我希望我能够清楚地解释清楚 下面是我的xaml代码

<phone:PhoneApplicationPage
x:Class="SmartParking.History"
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"
xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"   
mc:Ignorable="d"
shell:SystemTray.IsVisible="True">
<phone:PhoneApplicationPage.ApplicationBar>
    <shell:ApplicationBar>
        <shell:ApplicationBar.MenuItems>
            <shell:ApplicationBarMenuItem IsEnabled="True" Text="Delete all" Click="DeleteAll_Click"/>
        </shell:ApplicationBar.MenuItems>
        <shell:ApplicationBarIconButton IconUri="/Assets7/AppBar/delete.png" IsEnabled="True" Text="Delete" Click="Delete_Click" />
        <shell:ApplicationBarIconButton IconUri="/Assets8/AppBar/feature.search.png" IsEnabled="True" Text="Search"/>
    </shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>

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

    <!--TitlePanel contains the name of the application and page title-->
    <StackPanel Grid.Row="0" Margin="12,17,0,28">
        <TextBlock Text="Smart Parking" Style="{StaticResource PhoneTextNormalStyle}"/>
        <TextBlock Text="History" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>
    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <ListBox x:Name="ListData" SelectionChanged="ListData_SelectionChanged">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock x:Name=  "DateTxt"  Text="{Binding Date}"   TextWrapping="Wrap" />
                        <TextBlock x:Name=  "TimeTxt"  Text="{Binding Time}"  TextWrapping="Wrap" />
                        <TextBlock x:Name=  "ZoneTxt"  Text="{Binding Zone}"  TextWrapping="Wrap"/>
                        <TextBlock x:Name=  "FloorTxt" Text="{Binding Floor}" TextWrapping="Wrap"/>
                        <TextBlock x:Name=  "LatTxt"   Text="{Binding latitude}" TextWrapping="Wrap"  />
                        <TextBlock x:Name=  "LongTxt"  Text="{Binding longtitude}" TextWrapping="Wrap" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</Grid>

1 个答案:

答案 0 :(得分:0)

您可以按如下方式在文本框中添加边距 -

                <StackPanel Orientation="Horizontal">
                    <TextBlock x:Name=  "DateTxt"  Text="{Binding Date}"   TextWrapping="Wrap" Margin="10,0,10,0" />
                    <TextBlock x:Name=  "TimeTxt"  Text="{Binding Time}"  TextWrapping="Wrap" Margin="10,0,10,0"/>
                    <TextBlock x:Name=  "ZoneTxt"  Text="{Binding Zone}"  TextWrapping="Wrap" Margin="10,0,10,0"/>
                    <TextBlock x:Name=  "FloorTxt" Text="{Binding Floor}" TextWrapping="Wrap" Margin="10,0,10,0"/>
                    <TextBlock x:Name=  "LatTxt"   Text="{Binding latitude}" TextWrapping="Wrap" Margin="10,0,10,0" />
                    <TextBlock x:Name=  "LongTxt"  Text="{Binding longtitude}" TextWrapping="Wrap" Margin="10,0,10,0"/>
                </StackPanel>

此处,可以通过以下方式定义保证金 -

Margin="<Left>, <Top>, <Right>, <Bottom>"

例如。 - 保证金=&#34; 5,10,15,20&#34;

Margin="<Horizontal>, <Vertical>" - 这里水平意味着左边的边距&amp;正确而垂直意味着顶部和底部的保证金。底部 例如。 - 保证金=&#34; 5,10&#34;

Margin="<All Sides>" - 所有方面均适用相同的保证金 例如。 - 保证金=&#34; 10&#34;