Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello all,

I need to send ListView SelectedItems from view to ViewModel. now I have a code it is getting and sending single SelectedItem from view to ViewModel..
I tried few examples but I not getting required.


here is my ListView window.xaml:
XML
<ListView x:Name="ParameterList" HorizontalAlignment="Stretch" 
                  ItemsSource="{Binding Source={StaticResource SortedParameters}}"
                  SelectionMode="Multiple" SelectedItem="{Binding SelectedParameter}"  
                  Grid.Row="1" Grid.Column="2"
                  Width="200">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Description}" Width="200"/>
                </GridView>
            </ListView.View>
        </ListView>

The SelectedParameter addresses the ViewMode.cs:
C#
private IParameter selectedParameter;
        public IParameter SelectedParameter
        {
            get { return selectedParameter; }
            set
            {
                selectedParameter = value;
                OnPropertyChanged(nameof(SelectedParameter));
            }
        }


When user click the button in the Window.xmal:
XML
<Button x:Name="plotGraph" Grid.Row="0" Content="Plot Graph" Padding="5" Margin="5"
                    HorizontalAlignment="Stretch" VerticalAlignment="Top"
                    Command="{Binding Plotgraph}"/>


Then, I need to Execute the method using those SelectedItems(Plotgraph.cs),
C#
viewModel.GetParameterValues(viewModel.SelectedParameter.Name); 


In ViewModel.cs
C#
public Dictionary<int, double> GetParameterValues(string name)
{
    return PlotParameter = Model.GetParameterValues(name);
}


Help me from this...
Thanks in advance..

What I have tried:

https://github.com/xamarin/recipes/tree/master/cross-platform/xamarin-forms/Controls/multiselect/Multiselect
http://thatcsharpguy.com/post/multiselect-listview-mvvm-en/
http://stackoverflow.com/questions/8460855/selecting-multiple-row-of-items-in-a-listview
Posted
Updated 24-Aug-16 9:25am
v2

1 solution

My preference would be a behavior. Here is a link that might help: .net - Synchronizing multi-select ListBox with MVVM - Stack Overflow[^]

I would have rolled my own to do this, but this should work. My own would not have required a reference to System.Windows.Interactivity. Remember to add to your project.
 
Share this answer
 
Comments
nanda kishor 26-Aug-16 3:11am    
Thank you very much for your valuable suggestion...Its working and also getting data...
Clifford Nelson 26-Aug-16 9:41am    
You should mark the question solved and up=vote if you found it helpful

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900