2015-04-03 68 views
0

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> 

正如你所看到的,有問題的組合框甚至沒有使用文本字段更不用說結合它。什麼導致了錯誤? (見下文。我的問題解決了,但因爲我無法找到任何其他地方該有同樣的解決了這個問題,我決定在這裏發佈的解決方案的情況下,它可以幫助別人了。)

回答

0

的關鍵到解決方案是風格。在代碼中,樣式由更多的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>