HI ,
I use the following code for data grid and I need put button on the side of the data grid
which you can select line on the data grid and if you press the button this line is going up in the order of the list
for example if I select the third line and press on the button the up button the third and the second line
is replaced and etc,how should I do that in mvvm?
<Grid><StackPanel Orientation="Horizontal"><Button Content="UP" Height="30" Width="50" Margin="0,0,0,0"/></StackPanel><StackPanel Orientation="Vertical" Width="500" Height="250"><DataGrid ItemsSource="{Binding Items}" AutoGenerateColumns="False" RowHeaderWidth="0" Height="420" ><DataGrid.Columns><DataGridTextColumn Binding="{Binding Column1}" Header="1" Width="*" /><DataGridTextColumn Binding="{Binding Column2}" Header="2" Width="*" /><DataGridTextColumn Binding="{Binding Column3}" Header="3" Width="*" /><DataGridTextColumn Binding="{Binding Column4}" Header="4" Width="*" /><DataGridTextColumn Binding="{Binding Column5}" Header="5" Width="*" /></DataGrid.Columns></DataGrid></StackPanel></Grid>
internal class ViewModel:INotifyPropertyChanged { public ViewModel() { this.Items = new List<MyClass>(); //row 1: this.Items.Add(new MyClass {Column2 = "FirstName" ,Column3 = "LastName",Column4 ="Customer1",Column5 = "Emp1"}); //row 2: this.Items.Add(new MyClass { Column2 = "FirstName2", Column3 = "LastName2", Column4 = "Customer2", Column5 = "Emp2" }); //row 3: this.Items.Add(new MyClass { Column2 = "FirstName3", Column3 = "LastName3", Column4 = "Customer3", Column5 = "Emp3" }); var selectedRows = this.Items.Where(i => i.Column1.Equals(true)); } public IList<MyClass> Items { get; set; } public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); } } }