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

  • SEARCH
  • Home
  • 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 942921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:21:03+00:00 2026-05-15T22:21:03+00:00

I have an action Edit in my WPF application, which is bound to items

  • 0

I have an action Edit in my WPF application, which is bound to items in a ListView control, i.e. it is executed when an item is double clicked or the Edit button in the toolbar is clicked. This action in turn displays a modal window with the editing stuff.

Now when I select multiple items in the list, click Edit, the items stay selected in the background, also, when I close the dialog, they are still selected in the sence that their background is blue. However, they seem to be not selected in the sence that the Edit button is disabled in the toolbar (the Edit action’s CanExecute method simply checks FileList.SelectedIndex != -1. What’s more, the “selected” items won’t get deselected when I click some other list item – they only get deselected when I explicitly click on them one by one – it’s as if the blue background is stuck on them.

My code does not use any fancy ListView styles or what not, so what could be causing this ?
I can post my code upon request, but it is pretty much standard.

EDIT:

After cutting down my code I finally found what’s causing this issue. After showing the dialog, I edit the items in the data bound collection, so that the ListView would get updated (i.e. replace the bound objects to new objects). The question is, why is this causing a problem and how should I resolve it ?

  • 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-05-15T22:21:03+00:00Added an answer on May 15, 2026 at 10:21 pm

    Something in your code must be causing this issues. Below is a sample which behaves as expected.

    XAML:

    <Window x:Class="TestDemo.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300">
    
        <Window.Resources>
            <RoutedUICommand x:Key="EditItemsCommand" Text="Edit Items" />
        </Window.Resources>
    
        <Window.CommandBindings>
            <CommandBinding 
                Command="{StaticResource EditItemsCommand}" 
                CanExecute="EditItems_CanExecute" 
                Executed="EditItems_Executed" />
        </Window.CommandBindings>
    
        <StackPanel>
            <Button Name="_editButton" Content="Edit" Command="{StaticResource EditItemsCommand}" />
            <Button Content="Unselect all" Click="OnUnselectAll" />
            <ListView 
                Name="_listView"
                ItemsSource="{Binding Path=Items}" 
                SelectionMode="Extended"
                MouseDoubleClick="OnListViewMouseDoubleClick">
            </ListView>
        </StackPanel>
    </Window>
    

    Code behind:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Windows;
    using System.Windows.Input;
    
    namespace TestDemo
    {
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
    
                DataContext = this;
            }
    
            public IEnumerable<string> Items
            {
                get 
                {
                    for (int i = 0; i < 10; i++) { yield return i.ToString(); }
                }
            }
    
            private void EditItems_CanExecute(object sender, CanExecuteRoutedEventArgs e)
            {
                e.CanExecute = _listView != null && _listView.SelectedItems.Count > 0;
            }
    
            private void EditItems_Executed(object sender, ExecutedRoutedEventArgs e)
            {
                EditWindow editWindow = new EditWindow();
                editWindow.EditItems = _listView.SelectedItems.Cast<string>();
                editWindow.ShowDialog();
            }
    
            private void OnListViewMouseDoubleClick(object sender, MouseButtonEventArgs e)
            {
                _editButton.Command.Execute(null);
            }
    
            private void OnUnselectAll(object sender, RoutedEventArgs e)
            {
                _listView.SelectedItem = null;
            }
        }
    }
    

    XAML:

    <Window x:Class="TestDemo.EditWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="EditWindow">
        <ListBox ItemsSource="{Binding Path=EditItems}" />
    </Window>
    

    Code behind:

    using System;
    using System.Collections.Generic;
    using System.Windows;
    
    namespace TestDemo
    {
        public partial class EditWindow : Window
        {
            public EditWindow()
            {
                InitializeComponent();
    
                DataContext = this;
            }
    
            public IEnumerable<string> EditItems { get; set; }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Index view I have the usual Edit, Details and Delete links. I've
I am using MVC 2. I have 2 controllers called Application and Note. The
I have an action called Sessies. In this action i am creating 'Sessies' objects
I have a Widget i am working on, that allows the user to have
I have a strongly typed view that is using a viewmodel I created. I
I find my edit actions in CakePHP controllers get messy pretty quickly, and I'd
I have a class Document (in a mongodb collection) and persist various sub classes
I have a route in my asp.net mvc 2 site that looks like this
The scenario is this: I have some users on my site. A user has
I am trying to create an action ( :my_action ) route that will allow

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.