2017-06-07 127 views
0

我有一个TextBox绑定到string属性ViewModel,我有一个ButtonCommand。现在我想通过属性本身如果可能作为CommandParameter。 这可能吗?Xaml通过绑定属性到命令

的XAML部分:

<TextBox Text="{Binding FilePath, UpdateSourceTrigger=PropertyChanged}"/> 
<Button Command="{Binding BrowseCommand}" CommandParameter="{Binding FilePath}" Content="..." /> 

而且Command看起来是这样,但我有什么类型把RelayCommand<?>,而不是什么,我需要的CommandParameter结合?

public ICommand BrowseCommand => this.browseCommand ?? (this.browseCommand = new RelayCommand<?>(this.Browse)); 
+0

filepath是字符串类型我承担? – WBuck

+0

是的,我想通过属性本身,而不是它的价值(如果可能的话) –

+0

这是不可能的。 {绑定}解析*值*。 – mm8

回答

1

这应该如果您正在使用从MvvmLight的RelayCommand<T>类工作:

public ICommand BrowseCommand => this.browseCommand ?? (this.browseCommand = new RelayCommand<string>(this.Browse)); 

private void Browse(string obj) 
{ 

} 
+0

感谢您的回答,我也尝试过,它的工作原理,但'obj'拥有财产的价值,而不是财产本身。我正在寻找一种方式,以便在'Browse'内部,我可以使用'obj'作为它的属性(例如,设置'obj'会显示在UI –

+1

这不支持。您将获得属性的*值*作为命令参数传递 – mm8

+0

所以没有办法传递实际属性?好吧,谢谢你的回答 –