XAML绑定到Collection [index] .ObjectProperty

Joe*_*ger 4 xaml binding

我的VM中有一个可观察的对象集合.我想绑定到文本块中列表中特定项的属性,如下所示:

Binding="{MyVMCollection[0].Description}"
Run Code Online (Sandbox Code Playgroud)

但是这种语法不起作用.有可能做我想要的事情,如果是这样,怎么样?

谢谢!

N_A*_*N_A 6

您错过了Binding关键字,我认为您还需要使用Path.

Binding="{Binding Path=MyVMCollection[0].Description}"
Run Code Online (Sandbox Code Playgroud)

  • 假设你的`DataContext`包含一个以'MyVMCollection`作为属性的对象,你就会像我写的一样使用它.如果您的`DataContext` _is_`MyVMCollection`那么您将不得不做`Path = [0] .Description`(我认为). (2认同)