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

Two eventtocommands referencing wrongly (Using mvvmlight and system.windows.interactivity)

$
0
0
At the moment while using MVVM I have 2 different comboboxes that require the event "SelectionChanged" to be used to trigger different commands that are defined in 2 different viewmodels for 2 different views, however after opening both views, one of the combobox triggers one command partially before jumping to the other command stated in the second viewmodel. Here are the codes for both commands and eventtocommands.
    //MainWindow
        Collection Database1= Application.Current.Resources["MemoryTransfer"] as MemoryCollection;
    //First Command that is triggered by the first combobox "SelectionChanged"
        void Swap(object parameter)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            Database1.Clear(); //Where the program jumps to the second command

            Swapworker.RunWorkerAsync();

            Application.Current.Resources["Database"] = Database1;
        }

    //Window1
        Collection buffer = Application.Current.Resources["MemoryTransfer"] as Collection;
    public ObservableCollection<Datatype> Placeholder { get; set; }
    /*Second command that supposed to be triggered by a second combobox "SelectionChanged" being triggered on after first command*/
        void StartChange(object parameter)
        {
            Placeholder.Clear();
            Placeholder.Add(buffer[CountStart]);
        }

And here is how both interaction triggers are written, both under the respective comboboxes
<!--First combobox--><i:Interaction.Triggers><i:EventTrigger EventName="SelectionChanged"><cmd:EventToCommand Command="{Binding SwapCommand}" PassEventArgsToCommand="false" /></i:EventTrigger></i:Interaction.Triggers><!--Second combobox--><i:Interaction.Triggers><i:EventTrigger EventName="SelectionChanged"><cmd:EventToCommand Command="{Binding StartChangeCommand}"  PassEventArgsToCommand="false" /></i:EventTrigger></i:Interaction.Triggers>

SwapCommand is a delegatecommand for swap
and StartChangeCommand is a delegatecommand for startchange.

I found out that placing my Database1.Clear(); anywhere triggers the jump to StartChange command. I still do not know the reason as to why or how to fix it.

Viewing all articles
Browse latest Browse all 18858

Trending Articles



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