2017-08-16 57 views
0

我正在努力解决一个问题。我有一个XamComboEditor,我想在运行时的代码背后知道MVVM源代码。如何获取项目来源XamComboEditor的代码隐藏在Wpf中

<ig:XamComboEditor x:Name="Country" EmptyText="Select ..." DisplayMemberPath="CountryName" SelectedValuePath="CountryCode" PreviewLostKeyboardFocus="Country_PreviewLostKeyboardFocus" 
      ItemsSource="{Binding Path=DataCountry}" IsEnabled="{Binding IsEdit,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" 
      Grid.Row="0" SelectedItem="{Binding SelectedCountry, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Width="200" Height="40" /> 

var be = Country.GetBindingExpression(getComboBox.ItemsSource); 
if (be != null && be.ParentBinding != null) 
{ 
    sourceProperty = be.ParentBinding.Path.Path; 
    if (sourceProperty.Contains('.')) 
    { 
     var spliteed = sourceProperty.Split('.'); 
     sourceProperty = spliteed[1]; 
    } 
} 

如何获得MVVM属性名称

回答

1

GetBindingExpression方法需要DependencyProperty

var be = Country.GetBindingExpression(XamComboEditor.ItemsSourceProperty); 
if (be != null && be.ParentBinding != null) 
... 
+0

谢谢。大 –