我在wp7中第二次打开弹出窗口时没有清除列表框项目

时间:2012-04-17 11:16:23

标签: windows-phone-7

我在弹出窗口中使用了列表框。当我导航到弹出窗口第二次列表框项目未清除时。清除列表框项目..请帮助我查询此问题。 这是我用过的代码

 <ListBox Background="LightYellow" ItemsSource="{Binding Mode=OneWay, Path= MyPrintingSheetItems}"  Grid.ColumnSpan="2" Grid.Row="6"  Height="270" HorizontalAlignment="Stretch" Margin="0,0,0,0" Name="ListBox2" VerticalAlignment="Top" Width="440" >
          <ListBox.ItemContainerStyle>
                                   <Style TargetType="ListBoxItem">
                                        <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
                                    </Style>
                                </ListBox.ItemContainerStyle>
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <Border BorderThickness="0,0,0,3" BorderBrush="pink" >

                                    <Grid >
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="170"/>
                                    <ColumnDefinition Width="90"/>
                                    <ColumnDefinition Width="90"/>
                                    <ColumnDefinition Width="90"/>
                                </Grid.ColumnDefinitions>
                                        <TextBlock Name="lblps" Height="50" Text="{Binding PrintingSheet}" FontSize="26" Grid.Column="0"  VerticalAlignment="Center" Margin="0,0, 0, 0" HorizontalAlignment="Center" Foreground="Black" />
                                        <TextBlock Height="50" Name="lblnrml" Text="{Binding Normal}" FontSize="26" Grid.Column="1" Margin="0,0, 0, 0" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Black" />
                                        <TextBlock Height="50" Name="lblhvy" Text="{Binding Heavy}" FontSize="26" Grid.Column="2" Margin="0,0, 0, 0" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Black" />
                                        <TextBlock Height="50" Name="lblmetal" Text="{Binding Metal}" FontSize="26" Grid.Column="3" Margin="0,0, 0, 0" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Black" />

                                        </Grid>
                                </Border>

                                </DataTemplate>

                            </ListBox.ItemTemplate>
                        </ListBox>

按钮点击事件代码:

Private Sub btnAdd_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)

        PopUp.IsOpen = True
        btnAdd.IsEnabled = False
        btnBack.IsEnabled = False
        btnDelete.Visibility = Windows.Visibility.Collapsed
        txtLength.Text = ""
        txtwidth.Text = ""
        txtsize.Text = ""
        CheckBox1.IsChecked = False
        ListBox1.IsEnabled = False
        TitleLayOut.Opacity = 0.5
        LayoutRoot.Background = BrushFromColorName("#AA000000")
        txtSearch.IsEnabled = False
        btnSearch.IsEnabled = False
        ListBox1.Opacity = 0.5

    End Sub

1 个答案:

答案 0 :(得分:0)

当你打开弹出窗口时,通过

清除它
listBox1.Items.Clear();