【发布时间】:2023-03-27 10:37:01
【问题描述】:
您好,我有一个文本框,其中包含最初通过数据绑定填充为值的文本。
<TextBox Name="EmployeeName" Text="{Binding Employee.Name}" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Margin="8,0,0,0"/>
我有一个刷新按钮可以将其重置为原始值,还有一个保存按钮可以保存更改。
<Button Name="RefreshEmployeeName" Content="Refresh" Grid.Column="2" Grid.Row="0" Width="50" Height="25" Command="{Binding RefreshEmployeeNameCommand}" CommandParameter="{Binding Text, ElementName=EmployeeName}"/>
<Button Name="SaveEmployeeName" Content="Refresh" Grid.Column="2" Grid.Row="0" Width="50" Height="25" Command="{Binding SaveEmployeeNameCommand}" CommandParameter="{Binding Text, ElementName=EmployeeName}"/>
我在我的视图模型中使用 MVVM lightand 我创建了 2 个 RelayCommands
SaveEmployeeNameCommand = new RelayCommand(SaveEmployee);
RefreshEmployeeNameCommand = new RelayCommand(RefreshEmployee);
private void SaveEmployee()
{
//这里如何从文本框(命令参数)中获取值 }
【问题讨论】:
标签: silverlight mvvm mvvm-light