【发布时间】:2013-08-15 15:58:43
【问题描述】:
我尝试使用此代码在ComboBox 中绑定一个列表:
var template = new DataTemplate();
var comboBoxFactory = new FrameworkElementFactory(typeof(ComboBox));
template.VisualTree = comboBoxFactory;
Binding b = new Binding();
b.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, this.GetType(), 1);
b.Path = new PropertyPath("DataContext");
comboBoxFactory.SetBinding(ComboBox.ItemsSourceProperty, b);
comboBoxFactory.SetBinding(ComboBox.SelectedItemProperty, new Binding("ClassRoom"));
当我简单地启动窗口时它正在工作,如下所示:
winListOrgane ee = new winListOrgane();
ee.Show();
但是当我尝试将此窗口放入网格容器中时,它不起作用:
_currentWindow = (ModelPage)Activator.CreateInstance(pPage.GetType());
_currentWindow.SetParam(genParam);
_currentWindow.InitPage();
object content = _currentWindow.Content;
_currentWindow.Content = null;
_containerPage.Children.Add((UIElement)content);
我可以做些什么来解决这个问题?
谢谢
最好的问候, 弗雷德里克
【问题讨论】:
标签: wpf binding combobox window