'Click'에 해당되는 글 1건

  1. 2017.07.17 MVVM Button Click Command 사용법
wpf2017. 7. 17. 16:54

일단 Command를 만든다.

1
2
        private bool _deleteCommand = true;
        public RelayCommand DeleteCommand { get; private set; }
 


ViewModel 생성자에 넣기

1
2
3
4
5
 public MainViewModel()
        {
            DeleteCommand = new RelayCommand(ExcuteDeleteCommand, () => _deleteCommand);
            OrderMenuList = new ObservableCollection<OrderMenu>();
        }



1
2
3
4
 private void ExcuteDeleteCommand()
        {
            OrderMenuList.RemoveAt(OrderMenuList.Count - 1);
        }


xaml코드에는


1
<Button x:Name="xdelete" Content="삭제"  Height="50" Margin="20" Command="{Binding DeleteCommand}" />


여러가지 파라미터를 사용하고 싶으면 여기 참고

https://msdn.microsoft.com/en-us/magazine/dn237302.aspx

Posted by 동동(이재동)