Xaml 方向更改后列表框内控件的宽度不更改

Xaml 方向更改后列表框内控件的宽度不更改,xaml,layout,windows-phone-7.1,device-orientation,Xaml,Layout,Windows Phone 7.1,Device Orientation,我在stackpanel中有一个网格,它在一个列表框中。 这个网格有一些控制元素,比如矩形和文本块。 它们在纵向上延伸到整个宽度,但在横向上没有 这是XAML: <ListBox Name="PassList" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"> <ListBox.ItemTemplate>

我在stackpanel中有一个网格,它在一个列表框中。 这个网格有一些控制元素,比如矩形和文本块。 它们在纵向上延伸到整个宽度,但在横向上没有

这是XAML:

<ListBox Name="PassList" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">

                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel HorizontalAlignment="Stretch">
                                    <Grid Name="StackPanelWidth" Width="{Binding ElementName=PassList, Path=ActualWidth}">
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="40"/>
                                            <RowDefinition Height="40"/>
                                            <RowDefinition Height="40"/>
                                            <RowDefinition Height="40"/>
                                            <RowDefinition Height="20"/>
                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="10"/>
                                            <ColumnDefinition Width="{Binding ElementName=StackPanelWidth, Path=ActualWidth}"/>
                                            <ColumnDefinition Width="10"/>
                                        </Grid.ColumnDefinitions>

                                        <Rectangle Fill="White"
                                                   Grid.Row="0"
                                                   Grid.Column="1"
                                                   HorizontalAlignment="Stretch"
                                                   VerticalAlignment="Stretch"
                                                   RadiusX="10"
                                                   RadiusY="10"
                                                   />

                                        <Rectangle Fill="White"
                                                   Grid.Row="0"
                                                   Grid.Column="1"
                                                   HorizontalAlignment="Stretch"
                                                   VerticalAlignment="Stretch"
                                                   Margin="0,10,0,0"
                                                   />

                                        <Rectangle Fill="DarkGray"
                                                   Grid.Row="0"
                                                   Grid.Column="1"
                                                   Height="1"
                                                   VerticalAlignment="Bottom"
                                                   />

                                        <TextBlock Name="Country"
                                                   Grid.Row="0"
                                                   Grid.Column="1"
                                                   HorizontalAlignment="Left"
                                                   Margin="10,0,0,0"
                                                   VerticalAlignment="Center"
                                                   Text="{Binding Country}"
                                                   Foreground="Black"
                                                   FontWeight="Bold"
                                                   />


                                        .............
                                        .............

                                    </Grid>
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>

.............
.............
我的代码有什么问题吗? 任何帮助都将不胜感激


谢谢。

你为什么要这样做

在这里,您以某种方式指定了宽度,因为它不会调整大小

此外,stackpanel将自动调整其子宽度,因此如果您正试图这样做,则无需指定绑定