我有一個帶有命令綁定並使用Prism庫的文本塊。使用命令綁定的多個參數
這是XAML PARTH:
<TextBlock Margin="0,10,0,0">SocialSecurityNumer:</TextBlock>
<TextBox Name="SSNText" GotFocus="TextBox_GotFocus" Text="{Binding SSN, UpdateSourceTrigger=PropertyChanged}" Margin="0,3,0,0"/>
這是視圖模型背後:
public FindViewModel()
{
var eventAggregator = ServiceLocator.Current.GetInstance<IEventAggregator>();
FindCommand = new DelegateCommand(
() => eventAggregator.GetEvent<SSNChangedEvent>().Publish(SSN),
() => !string.IsNullOrWhiteSpace(Kennitala)
);
}
public DelegateCommand FindCommand { get; set; }
private string ssn;
public string SSN
{
get { return ssn; }
set
{
if (ssn== value)
return;
ssn = value;
RaisePropertyChanged(() => SSN);
FindCommand.RaiseCanExecuteChanged();
}
}
這是偵聽此事件觸發和火起來與SSN一個函數作爲GridViewModel參數
public class GridViewModel : NotificationObject
{
public GridViewModel()
{
var eventAggregator = ServiceLocator.Current.GetInstance<IEventAggregator>();
eventAggregator.GetEvent<SSNChangedEvent>().Subscribe(GetData);
}
public ObservableCollection<Investment> Investments { get; set; }
private void GetData(string ssn)
{
var list = GeniusConnection.GetDataFromWebService(ssn);
Investments = new ObservableCollection<Investment>(list);
RaisePropertyChanged(() => Investment);
}
}
我如何可以添加其他參數,例如日期時間參數,這讓我困惑的部分是:
FindCommand = new DelegateCommand(
() => eventAggregator.GetEvent<SSNChangedEvent>().Publish(SSN),
() => !string.IsNullOrWhiteSpace(Kennitala)
);
此發佈功能,只需要一個參數,爲此我不知道怎樣才能輕鬆地添加多個paramters ??。
請閱讀[編輯幫助(http://stackoverflow.com/editing-help),並確保正確地格式化代碼下一次。 –
格式化有問題嗎? – aghaux
好了,不一樣了,但有... –