I am developing an windows phone app and I want to show six textblock in a listbox but The problem is all 6 values are sticked to each other. I want to give some spaces in between so that they look better when shown. Like for example what they look like currently is
Date|time|floor|zone|latitude|longtitude
and I would like them to look like
Date | Time | floor | zone | latitude | longtitude
I hope I am able to explain it clearly below is my xaml code
<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>
You can add margins to the textboxes as follows-
<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>
Here, margin can be defined in the following ways-
Margin="<Left>, <Top>, <Right>, <Bottom>"
eg. - Margin="5,10,15,20"
Margin="<Horizontal>, <Vertical>"
- here horizontal means margin on left & right while Vertical means margin on top & bottom eg. - Margin="5,10"
Margin="<All Sides>"
- same margin will be applied on all sides eg. - Margin="10"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.