Command 传参的几种方式
生活随笔
收集整理的這篇文章主要介紹了
Command 传参的几种方式
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Command可以根據CommandParameter傳參
關鍵代碼
public ICommand SubmitCommand => _submitCommand; private RelayCommand _submitCommand = new RelayCommand(new Action<object>(ShowMessage)); private static void ShowMessage(object obj) {MessageBox.Show(obj.ToString()); } <TextBox Name="textBox1"></TextBox> <Button Command="{Binding SubmitCommand}" CommandParameter="{Binding ElementName=textBox1,Path=Text}" Content="提交參數"></Button>也可以這樣綁定
<Label Grid.Row="0">姓名:</Label> <TextBox Name="name" Grid.Row="0" Grid.Column="1" Text="{Binding Person.Name}"></TextBox> <Label Grid.Row="1">年齡:</Label> <TextBox Name="age" Grid.Row="1" Grid.Column="1" Text="{Binding Person.Age}"></TextBox> <Button Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Command="{Binding SubmitCommand}" CommandParameter="{Binding Person}" Content="提交參數"></Button>示例代碼
https://github.com/zLulus/NotePractice/tree/dev3/WPF/WpfDemo/Command
Command與Click的關系
Command用于后臺操作,click用于前臺展示、交互,可以共存
轉載于:https://www.cnblogs.com/Lulus/p/9726379.html
總結
以上是生活随笔為你收集整理的Command 传参的几种方式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html input日期值,input标
- 下一篇: 中国海洋大学计算机学院研究生导师,中国海