2014-11-06 51 views
1

需要在后面的代码中获取绑定对象的名称。以编程方式获取绑定名称

<telerik:RadGridView x:Name="grdCoverContent" AutoGenerateColumns="False" CanUserInsertRows="False" IsSynchronizedWithCurrentItem="True" 
              GridLinesVisibility="Horizontal" telerik:StyleManager.Theme="Windows8" VerticalAlignment="Top" 
              ShowGroupPanel="False" ItemsSource="{Binding CoverContentCollection, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True }" 
              SelectedItem="{Binding SelectedCoverContent,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged, Source={StaticResource CoverViewModel} }" RowHeight="30" CellValidating="grdCoverContent_CellValidating" > 

有没有什么办法让约束力的名称为 “CoverContentCollection”

在此先感谢。

回答

1

你需要的实际上是绑定的Path(实际上它是PropertyPathPath属性)。因此,只需获得绑定并访问其路径,如下所示:

var path = grdCoverContent.GetBindingExpression(ItemsControl.ItemsSourceProperty) 
          .ParentBinding.Path.Path; 

代码应该在窗口加载完成后运行。

相关问题