【发布时间】:2015-11-13 05:09:03
【问题描述】:
XAML
<ComboBox Grid.Column="1" Grid.Row="1" Height="23" HorizontalAlignment="Center" Margin="2,2,0,0" Name="comboBoxServer" VerticalAlignment="Top" Width="156" ItemsSource="{Binding ServerNameList, Mode=OneWay}" SelectedItem="{Binding Path=serverSelected, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding serverCommand}" CommandParameter="{Binding ElementName=comboBoxServer,Path=SelectedItem}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox
<ComboBox Grid.Column="1" Grid.Row="2" Height="23" HorizontalAlignment="Center" Margin="2,2,0,0" Name="comboBoxDBName" VerticalAlignment="Top" Width="156" ItemsSource="{Binding DBNameList}" SelectionChanged="comboBoxServer_SelectionChanged" SelectedItem="{Binding Path= fetchServer, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></ComboBox>
查看模型
父组合框:_ServerNameList 子组合框是:_DBNameList
ViewModel 构造函数
public BackUpViewModel()
{
BackUpContext servObj = new BackUpContext();
_ServerNameList = servObj.GetServers();
serverCommand = new RelayCommand(fetchServer);
}
public RelayCommand serverCommand { get; set; }
public void fetchServer(object server)
{
BackUpContext db= new BackUpContext();
serverSelected = server.ToString();
_DBNameList = db.GetDatabases(serverSelected);
}
当我在父组合框中选择第一个项目时,子组合框为空白。之后,当我在父组合框中选择第二个项目时,子项显示与父项中的第一个项目相关的项目。当我在 Parent 中选择第三个项目时,孩子会在父组合框中显示与第二个项目相关的项目。
我不知道为什么会这样。有什么建议吗?
【问题讨论】:
-
能否请包含您的 xaml?
-
@tagaPdyk:
-
@tagaPdyk:
组合框> -
请编辑您的问题并在此处添加 xaml。这里的问题是您的“第一个”选择,对吗?
-
@tagaPdyk : XAML 已添加到问题中。