2009-03-03 108 views
1

我有以下問題:
有一對夫婦字符串屬性的一類
有這樣的實體類WPF 2組合框綁定問題

的集合,集合顯示在樹的左邊一些窗戶和細節顯示在右側。我將所選節點的字符串屬性綁定到組合框中。
第一組合框總是具有相同的ItemsSource但第二個的ItemsSource取決於第一個組合的的SelectedItem ...

<ComboBox 
    Grid.Column="1" 
    SelectedIndex="0" 
    x:Name="cbClass" 
    Style="{DynamicResource ComboBoxValidationError}" 
    SelectedValue="{Binding Path=Description.Node.ClassName, ElementName=userControl, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
    ItemsSource="{Binding Source={StaticResource classesProvider}}" 
    Width="Auto" 
    Height="Auto" 
    DisplayMemberPath="Description" 
    SelectedValuePath="FQN" /> 

<ComboBox 
    Grid.Column="1" 
    SelectedIndex="0" 
    Grid.Row="1" 
    x:Name="cbMethod" 
    SelectedValue="{Binding Path=Description.Node.MethodName, ElementName=userControl, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,diag:PresentationTraceSources.TraceLevel=High}" 
    ItemsSource="{Binding Path=SelectedItem.Methods, ElementName=cbClass, Mode=Default,diag:PresentationTraceSources.TraceLevel=High}" 
    Style="{DynamicResource ComboBoxValidationError}" 
    Width="Auto" 
    Height="Auto" 
    SelectedValuePath="Name" 
    DisplayMemberPath="Description" /> 

現在,當我在樹中創建新的節點,這兩個字符串屬性具有空引用。當第一個組合改變它對於NEW節點的SelectedItem時,第二個ComboBox將null綁定到在樹中創建新節點之前選擇的OLD節點的字符串值......我想知道我應該在這種情況下做什麼?

回答

1

我剛剛找到答案。
綁定是按照其聲明的順序通知的,WPF不會分析綁定的依賴關係:) 因此,交換ComboBoxes的聲明解決了這個問題......在這種情況下可以接受,因爲我將這些ComboBoxes手動設置爲Grid Grid.Row和Grid.Column ... 雖然解決方案不是很令人滿意,但它的工作原理!