当前位置: 代码迷 >> Windows Mobile >> ListBox 布局,怎么每行包括两个并排控件,宽度不同
  详细解决方案

ListBox 布局,怎么每行包括两个并排控件,宽度不同

热度:477   发布时间:2016-04-25 07:14:52.0
ListBox 布局,如何每行包括两个并排控件,宽度不同?
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>
  相关解决方案