Windows Phone 7 - 键盘无缘无故显示

时间:2014-01-31 15:23:21

标签: windows-phone-7 soft-keyboard

所以我有一个带有模板的列表框,其中我绑定了一个名为“TotalDebits”的ObservableCollection对象。

我有两种删除项目的方法:

  • 逐个通过上下文菜单
  • 通过删除按钮和获取已检查对象的范围。

这有效:

private void Delete_Click(object sender, RoutedEventArgs e)
{
    DeleteDebit((DirectDebit)(((MenuItem)sender).DataContext));
}

private void DeleteDebit(DirectDebit ddb)
{
    TotalDebits.Remove(ddb);
}

private void delete_Click(object sender, EventArgs e)
{
    DeleteDebitList();
}

private void DeleteDebitList()
{
    try
    {
        foreach (var ddb in TotalDebits.ToList())
            if (ddb.IsChecked)
               TotalDebits.Remove(ddb);

    }
    catch
    {

    }
 }

在这两种情况下,项目都被正确删除,问题是,在第二种情况下,键盘在项目被删除后立即显示,绝对没有理由..当然我可以通过聚焦后立即隐藏它在列表上,但它看起来很难看,我希望我能找到一种方法来防止这个问题的发生。

编辑:

你可以在下面找到页面的xaml:

<controls:PivotItem Header="Direct Debit" >
            <Grid>
                <Grid.Resources>
                    <Storyboard x:Name="ListboxSizeIncrease">
                        <DoubleAnimation Storyboard.TargetName="DebitList" Storyboard.TargetProperty="Height"
                            From="475" To="380" Duration="0:0:.5"/>
                    </Storyboard>
                    <Storyboard x:Name="ListboxSizeDecrease">
                        <DoubleAnimation Storyboard.TargetName="DebitList" Storyboard.TargetProperty="Height"
                            From="380" To="475" Duration="0:0:.5"/>
                    </Storyboard>
                </Grid.Resources>

                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>

                <ListBox Grid.Row="0" x:Name="DebitList" Height="475" Margin="10,5,10,0" Tap="ListBox_Tap" ItemsSource="{Binding TotalDebits}" VerticalAlignment="Top" ItemContainerStyle="{StaticResource CustomListBoxItem}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Margin="0,2,0,2">
                                <Grid Margin="5,5,5,5" HorizontalAlignment="Stretch">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="60" />
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <CheckBox x:Name="CheckItem" Grid.Column="0" IsChecked="{Binding IsChecked}" Checked="CheckItem_Checked" Unchecked="CheckItem_Unchecked" />
                                    <TextBlock x:Name="DescriptionBlock" FontSize="24" Grid.Column ="1" Text="{Binding Description}" HorizontalAlignment="Left" VerticalAlignment="Center">   
                                    </TextBlock>
                                    <TextBlock FontSize="24" Grid.Column ="2" Text="{Binding Amount}" TextAlignment="Right"  HorizontalAlignment="Right" VerticalAlignment="Center"/>
                                </Grid>
                                <toolkit:ContextMenuService.ContextMenu>
                                    <toolkit:ContextMenu Name="ContextMenu" IsZoomEnabled="False">
                                        <toolkit:MenuItem Name="Edit" Header="Edit" Click="Edit_Click"/>
                                        <toolkit:MenuItem Name="Delete"  Header="Delete" Click="Delete_Click"/>
                                    </toolkit:ContextMenu>
                                </toolkit:ContextMenuService.ContextMenu>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
                <Border Margin="12,5,12,5" Grid.Row="1" Background="LightGray"/>
                <Grid Grid.Row="1" Margin="14,8,14,8">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>

                    <TextBlock Grid.Column="0" Text="TOTAL DIRECT DEBIT" FontSize="28" FontWeight="Bold" Foreground="DarkSlateGray"/>
                    <TextBlock Grid.Column="1" x:Name="TotalBlock" Text="{Binding TotalValue}" FontSize="28" FontWeight="Bold" Foreground="DarkSlateGray"/>
                </Grid>


                <Grid Grid.Row="2">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <Border Margin="12,5,12,5" Background="LightGray">
                    <Grid Grid.Row="0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="300"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <StackPanel Orientation="Vertical" Grid.Column="0">
                            <TextBlock Margin="10,0,0,0" Text="Description" FontSize="20" Foreground="DarkSlateGray"/>
                            <TextBox x:Name="DescriptionBox" FontSize="15" />
                        </StackPanel>
                        <Grid Grid.Column="1">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <StackPanel Orientation="Vertical" Grid.Column="0">
                                <TextBlock Margin="0,0,0,0" Text="Amount" Foreground="DarkSlateGray"/>
                                <TextBox x:Name="AmountBox" FontSize="15" />
                            </StackPanel>
                            <StackPanel Orientation="Vertical" Grid.Column="1">
                                <TextBlock Margin="10,0,0,0" Text="." Foreground="DarkSlateGray"/>
                                <TextBox x:Name="DecimalBox" Width="60" FontSize="15" MaxLength="2"/>
                            </StackPanel>
                        </Grid>
                    </Grid>
                    </Border>
                </Grid>

            </Grid>
        </controls:PivotItem>

0 个答案:

没有答案