上的属性绑定错误不具有任何绑定设置

问题描述:

Visual Studio是显示在输出以下错误:上的属性绑定错误不具有任何绑定设置

System.Windows.Data Error: 40 : 
    BindingExpression path error: 
    'Text' property not found on 'object' ''PropertyAppraisalWorkflowViewModel' (HashCode=35281714)'. BindingExpression:Path=Text; 
DataItem='PropertyAppraisalWorkflowViewModel' (HashCode=35281714); 
target element is 'ComboBox' (Name='cmbWorkflowView'); 
target property is 'Text' (type 'String') 

奇怪的是,我没有财产“文本”绑定(或甚至被使用)用于cmbWorkflowView控件。

这里是一个错误的说法有问题的XAML的截段:

<Grid Name="grdWorkflow"> 
     <Grid.Resources> 
      <Style TargetType="ComboBox" BasedOn="{StaticResource DefaultComboBox}" /> 
     </Grid.Resources> 

     <ComboBox DockPanel.Dock="Right" 
        Name="cmbWorkflowView" 
        ItemsSource="{Binding ViewOptions}" 
        SelectedItem="{Binding SelectedView}" 
        props:ComboBoxProperties.SelectionChangedCommand="{Binding SelectWorkflowView}" /> 
    </Grid> 

正如你所看到的,有问题的组合框甚至没有使用文本字段更不用说结合它。什么导致了错误? (见下文。我的问题解决了,但因为我无法找到任何其他地方该有同样的解决了这个问题,我决定在这里发布的解决方案的情况下,它可以帮助别人了。)

的关键到解决方案是风格。在代码中,样式由更多的XAML分隔。我已经忘记了对ComboBox与它相关联的风格。当我遵循风格来源时,我发现了以下内容。 (为了可读性而截断,实际样式更多地涉及。)

<Style x:Key="DefaultComboBox" TargetType="ComboBox"> 
     <Setter Property="Height" Value="{StaticResource DefaultControlHeight}" /> 
     <Setter Property="Text" Value="{Binding Path=Text}" /> 
     <Setter Property="Background" Value="{StaticResource ComboBoxEditableFieldBrush}" /> 
    </Style> 

样式绑定了“文本”属性。一旦我删除二传手的“文本”属性,错误消失。

<Style x:Key="DefaultComboBox" TargetType="ComboBox"> 
     <Setter Property="Height" Value="{StaticResource DefaultControlHeight}" /> 
     <Setter Property="Background" Value="{StaticResource ComboBoxEditableFieldBrush}" /> 
    </Style>