티스토리 뷰
반응형
[wpf/c#] mvvm light, CommandParameter 사용법
#Command사용 시 Parameter를 넘길 수 있다.
#View(xaml) - CommandParameter="aaaa"등과 같이 값을 넣어준다.
<TextBox Margin="10,0,0,0" Grid.Row="1" HorizontalAlignment="Left" Width="180" Height="30" Text="{Binding TextBoxText,UpdateSourceTrigger=PropertyChanged}" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="TextChanged" >
<i:InvokeCommandAction Command="{Binding OnTextChangedCommand}" CommandParameter="aaaaa" />
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
#ViewModel
//정의
public RelayCommand<string> OnTextChangedCommand { get; set; }
private void OnTextChangedCommandAction(string msg)
{
MessageBox.Show(TextBoxText);
}
//초기화
OnTextChangedCommand = new RelayCommand<string>((msg)=> OnTextChangedCommandAction(msg), null);
이렇게 간단하게 쓸 수 있다.
#mvvm #commandparameter #command #wpf #c#
반응형
'c#' 카테고리의 다른 글
[wpf/c#] mvvm 을 활용한 런처(전원 관리 및 파일 관리) 만들기(1/3) (0) | 2022.03.02 |
---|---|
[c#/wpf] UpdateSourceTrigger=PropertyChanged (mvvm 사용 시 바인딩 객체값이 변경되면 바로 반영하기) (0) | 2022.02.24 |
[wpf/c#] mvvm light를 이용한 간단한 샘플 프로그램(소스) (0) | 2022.02.24 |
[wpf/c#] MVVM 기본 개념 및 설명 (소스 기반) (0) | 2022.02.24 |
[wpf/c#/unity] Wake On Lan 사용하기(원격부팅) (0) | 2022.02.16 |
댓글
반응형