listbox的每行显示需要量个控件,即TextBlock和button,textblock在最左边左边,button在最右边显示,textblock的width长,button的内容为">"如下图:
该怎样布局我总是调不好?
我的xmal:
<ListBox x:Name="MainLongListSelector" Margin="0,0,10,0" ItemsSource="{Binding persons}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation ="Horizontal">
<Grid>
<TextBlock Text="{Binding DisplayName}"
Foreground="Black"
HorizontalAlignment="Left"
TextTrimming="WordEllipsis"
Margin="30,10,20,10"
VerticalAlignment="Center"
Style="{StaticResource PhoneTextLargeStyle}"/>
<Button x:Name="Detail"
HorizontalAlignment="Right" BorderThickness="0"
Margin="0,10,0,10"
VerticalAlignment="Bottom"
Click="Detail_Click">
<Button.Background>
<ImageBrush Stretch="Uniform" ImageSource="/Images/rightwards.png"/>
</Button.Background>
</Button>
</Grid>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
------解决方案--------------------
指定button的width属性。
------解决方案--------------------
首先,你把那个StackPanel去掉比较好
然后,给Grid设置两个列,把TextBlock放第一列,把Button放第二列。
------解决方案--------------------
<ListBox x:Name="MainLongListSelector"
Margin="0,0,10,0"
ItemsSource="{Binding person}">
<ListBox.ItemTemplate>