Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

ICommand Selected Item is failing mvvm

$
0
0

I'm working on a problem using MVVM. It is my first real attempt at it. I have a listview and the first selected item always fails to have the button enabled. However, the other ones work. I can verify through debugging that all of the criteria is met. The ode for the button is:

        private ICommand _updatedatabasecommand;
        public ICommand UpdateDataBaseCommand
        {
            get
            {
                if (_updatedatabasecommand == null)
                {
                    try
                    {
                        _updatedatabasecommand = new RelayCommand(
                            param => UpdateDatabaseExecute(),
                            param => (SelectedAddress != null && SelectedResponse != null && _address.Count != 0 && SelectedAddress.Success == 1 && SelectedResponse.AutoNumber != SelectedAddress.AutoNumber));
                    }
                    catch
                    {
                        _updatedatabasecommand = null;
                    }
                }
                return _updatedatabasecommand;
            }
        }

I've tried to add other things. I think it needs to be refreshed. I've added:

           

CommandManager.InvalidateRequerySuggested();

Also, since it is a list box, I've added:

            SelectedAddress = null;
            SelectedResponse = null;
These items aren't loaded until later in the program. It was giving me an exception error since they were empty.



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>