Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7942485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:59:10+00:00 2026-06-03T23:59:10+00:00

I have a textbox that is on the same screen as a listbox. When

  • 0

I have a textbox that is on the same screen as a listbox. When I remove an item from the listbox, which is bound to an observable collection, the textbox gains focus. Is there a way to stop this from happening?

I am using MVVM but am open to putting some code in the code behind if it fixes this problem.

EDIT:

CodeBehind View:

namespace Offload.WinPhone.Views
{
using System.Windows.Controls;
using Microsoft.Phone.Controls;

public partial class MainPageView : PhoneApplicationPage
{
    public MainPageView()
    {
        InitializeComponent();
    }

    private void QuickNoteBodyEditor_TextChanged(object sender, TextChangedEventArgs e)
    {
        var senderAsTextbox = (TextBox)sender;

        if (senderAsTextbox.Text.Length == 0)
            this.Focus();
    }
}

}

View:

<Grid x:Name="LayoutRoot" Background="Transparent" Margin="12,0,12,0">

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

    <TextBlock Text="OFFLOAD" FontFamily="Segoe WP Bold" Grid.Row="0"/>

    <ListBox x:Name="QuickNotes" Grid.Row="1" TabIndex="1">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Margin="0,5,0,5" Orientation="Vertical">
                    <TextBlock Style="{StaticResource PhoneTextExtraLargeStyle}" TextWrapping="Wrap" Text="{Binding Body}"/>
                    <TextBlock Style="{StaticResource PhoneTextAccentStyle}" Text="{Binding Timestamp, StringFormat='{}{0:dd MMM HH:mm}'}"/>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>  
    </ListBox>

    <TextBox x:Name="QuickNoteBodyEditor" AcceptsReturn="True" Grid.Row="2" InputScope="Chat" TextChanged="QuickNoteBodyEditor_TextChanged" IsTabStop="True" />

</Grid>

<phone:PhoneApplicationPage.ApplicationBar>
    <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">

        <shell:ApplicationBar.Buttons>
            <cal:AppBarButton IconUri="/AppFramework/Resources/Icons/Add.png" Text="Add" Message="AddQuickNote" />
            <cal:AppBarButton IconUri="/AppFramework/Resources/Icons/Delete.png" Text="Delete" Message="DeleteSelectedQuickNote" />
        </shell:ApplicationBar.Buttons>

        <shell:ApplicationBar.MenuItems>
            <cal:AppBarMenuItem Text="About" Message="NavigateToAddAccountView"/>
            <cal:AppBarMenuItem Text="Review" Message="NavigateToAddAccountView"/>
        </shell:ApplicationBar.MenuItems>

    </shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>

ViewModel:

public class MainPageViewModel : PropertyChangedBase
{
    private ObservableCollection<QuickNote> quickNotes;
    private string quickNoteBodyEditor;
    private QuickNote selectedQuickNote;

    // Databound Properties

    public string QuickNoteBodyEditor 
    {
        get { return quickNoteBodyEditor; }
        set { quickNoteBodyEditor = value; NotifyOfPropertyChange(() => QuickNoteBodyEditor); NotifyOfPropertyChange(() => CanAddQuickNote);}
    }

    public QuickNote SelectedQuickNote
    {
        get { return selectedQuickNote; }
        set { selectedQuickNote = value; NotifyOfPropertyChange(() => SelectedQuickNote); NotifyOfPropertyChange(() => CanDeleteSelectedQuickNote); }
    }

    public ObservableCollection<QuickNote> QuickNotes
    {
        get { return quickNotes; }
        set { quickNotes = value; NotifyOfPropertyChange(() => QuickNotes); }
    }

    // Guard Clauses

    public bool CanAddQuickNote 
    {
        get { return !string.IsNullOrWhiteSpace(quickNoteBodyEditor); } 
    }

    public bool CanDeleteSelectedQuickNote
    {
        get{ return selectedQuickNote == null ? false : true; }
    }

    // Constructors

    public MainPageViewModel()
    {
        GetQuickNotesFromIsolatedStorage();
        WatchWhatsGotFocus.StartWatching();
    }

    // Public Methods

    public void AddQuickNote()
    {
        if (CanAddQuickNote)
        {
            quickNotes.Add(new QuickNote(quickNoteBodyEditor, DateTime.Now));
            AddQuickNotesToIsolatedStorage();

            quickNoteBodyEditor = string.Empty;

            NotifyOfPropertyChange(() => QuickNoteBodyEditor);
            NotifyOfPropertyChange(() => QuickNotes);
        }
    }

    public void DeleteSelectedQuickNote()
    {
        if (CanDeleteSelectedQuickNote)
        {
            quickNotes.Remove(selectedQuickNote);
            AddQuickNotesToIsolatedStorage();

            selectedQuickNote = null;

            NotifyOfPropertyChange(() => SelectedQuickNote);
            NotifyOfPropertyChange(() => QuickNotes);
        }
    }

    private void GetQuickNotesFromIsolatedStorage()
    {
        quickNotes = IsolatedStorage.Get<ObservableCollection<QuickNote>>("QuickNoteList");
    }

    private void AddQuickNotesToIsolatedStorage()
    {
        IsolatedStorage.Add("QuickNoteList", quickNotes);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:59:12+00:00Added an answer on June 3, 2026 at 11:59 pm

    I had the same issue, a possible solution is to set the TextBox to disabled before modifying your collection and enable it afterwards again:

    TextBox.IsEnabled = false;
    ObservableCollection.Remove(object);
    TextBox.IsEnabled = true;
    

    I wouldn’t call it a clean approach, but it worked for me :).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a textbox that when you put focus into it, it drops down
I have this program that is reading the test string from a textbox and
I have a TextBox that is bound to my ViewModel. The TextWrapping property of
In WPF I have a screen for login which has a textbox for username
I have a textbox that I would like for only numbers. But if I
I have a textbox that i am binding to the viewmodel's string property. The
I have a TextBox that has the TextChanged event set declaratively. In some cases,
I have a textbox that accepts only these values: . , - $ m
I have a textbox that gets a decimal value say 10500.00 the problem is
Hi I have a textbox that takes a username input. When the user submits

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.