リストボックスのデータ テンプレートを動的に作成しようとしています。これは、カスタム UserControl 用です。この UserControl には、任意のタイプのIEnumerable<>を受け入れるDependencyPropertyがあります。
これは正常に動作します...しかし、出力は常に
- プロパティ/値
- プロパティ/値
オブジェクトに 2 つのプロパティが含まれている場合。しかし、プロパティを並べて配置したいと思います。お気に入り:
オブジェクト 1:
- プロパティ / 値 プロパティ / 値
オブジェクト 2:
- プロパティ / 値 プロパティ / 値
どこが間違っているのですか?最初に Stackpanel を作成し、Stackpanel で、ラベルを含む Dockpanels を作成しています。
現時点での外観を少しプレビューします。
したがって、これはデータテンプレートを作成するための私のコードです:
DataTemplate _NewData = new DataTemplate();
FrameworkElementFactory _template = new FrameworkElementFactory(typeof(StackPanel));
foreach (var _FProperty in view.CurrentItem.GetType().GetProperties())
{
FrameworkElementFactory _firstTemplateChild = new FrameworkElementFactory(typeof(DockPanel));
FrameworkElementFactory _childOneForDock = new FrameworkElementFactory(typeof(Label));
_childOneForDock.SetValue(Label.ContentProperty, _FProperty.Name);
_firstTemplateChild.AppendChild(_childOneForDock);
FrameworkElementFactory _childTwoForChild = new FrameworkElementFactory(typeof(Label));
_childTwoForChild.SetBinding(Label.ContentProperty, new Binding(_FProperty.Name));
_firstTemplateChild.AppendChild(_childTwoForChild);
_template.AppendChild(_firstTemplateChild);
}
_NewData.VisualTree = _template;
ListBoxInPopUp.ItemTemplate = _NewData;