2009-03-03 129 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 ... 虽然解决方案不是很令人满意,但它的工作原理!