如何在wpf中动态地将treeview添加到组合框中.. thakx ..
答案 0 :(得分:0)
你可以点击事件处理程序
来做到这一点 <TreeView Tag="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}" MouseClick="treeview_MouseClick" ItemsSource="{Binding Children}" x:Name="Tree">
使用Click事件可以获得ComboBox
private void treeview_MouseClick(object sender, RoutedEventArgs e)
{
try
{
TreeView treeview = sender as TreeView;
if(treeview == null)
return;
var combobox = treeview .Tag as ComboBox;
combobox .SelectedItem = treeview .SelectedItem;
}
catch (Exception e)
{
}
}