【发布时间】:2010-10-11 00:25:57
【问题描述】:
我有以下问题:
有一个类有几个字符串属性
有一个这样的类实体的集合
该集合显示在某些窗口左侧的树中,右侧显示详细信息。我正在将所选节点的字符串属性详细绑定到组合框。
第一个组合框始终具有相同的 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 节点的字符串值,这是在树中创建新节点之前选择的......我想知道在这种情况下我应该怎么做?
【问题讨论】:
标签: wpf data-binding combobox databound-controls