-2

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

 <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
4

1 回答 1

0

当您打开弹出窗口时,请通过

listBox1.Items.Clear();
于 2012-04-17T12:29:39.207 回答