문제

How to bind a collection to xamdatagrid on button click in wpf mvvm?

도움이 되었습니까?

해결책

XAML

   <Button Command="{Binding ButtonCommand}">Button</Button>
   <DataGrid ItemsSource="{Binding MyCollection}">
   ...
   configure columns to MyRowViewModel
   ...
   </DataGrid>

ViewModel

   public class MyViewModel
   {
     public ICommand ButtonCommand {get;set;}
     public ObservableCollection<MyRowViewModel> MyCollection {get;set;}
   }

and set in OnLoad:

   View.DataContext = viewModel;

and when command is called change your collection or create and wpf update your grid automatically

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top