ComboBox里面放置Treeview时,选中项的问题
在ComboBox里面用多级数据模板绑定TreeView时,选中一项后,ComboBox显示选中项,然后Treeview数据源改变,重新绑定TreeView。结果ComboBox里面的显示的文字没有变,但是选中项是改变了。各位大神,有什么解决方案吗?
页面代码:
<ComboBox Height="22" Name="cbxAccount" HorizontalAlignment="Center" VerticalAlignment="Center" DropDownOpened="cbxAccount_DropDownOpened" DropDownClosed="cbxAccount_DropDownClosed" Width="200">
<ComboBoxItem x:Name="cbItemTreeView" >
<ComboBoxItem.Content>
<controls:TreeView Name="tvAccount" MaxHeight="300" MinHeight="200" MinWidth="150" ItemTemplate="{StaticResource TreeItemTemplate}"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" SelectedItemChanged="tvAccount_SelectedItemChanged" BorderBrush="#FFA2ACB8">
</controls:TreeView>
</ComboBoxItem.Content>
</ComboBoxItem>
<ComboBoxItem x:Name="cbItemDisplay" >
</ComboBoxItem>
</ComboBox>
后台绑定的代码:
void InitTreeView() { this.accountTreeInfo.IsExpanded = true; List<AccountTreeInfo> list = new List<AccountTreeInfo>(); AccountTreeInfo newobj = new AccountTreeInfo(); newobj.AccountName = "请选择代理商"; AccountObj newInfoObj = new AccountObj(); newInfoObj.AccountID = 0; newobj.AccountObj = newInfoObj; list.Add(newobj); list.Add(this.accountTreeInfo); this.tvAccount.ItemsSource = list; this.cbItemDisplay.Content = "请选择代理商"; this.cbxAccount.SelectedItem = this.cbItemDisplay; this.SelectAccount = newobj.AccountObj; }