/// <summary> /// Get content for specified item based on specified column. /// </summary> object GetColumnContent(TreeViewColumn Column, TreeViewItem Item) { var a = default(DependencyObject); if (Column.Is <TreeViewTemplateColumn>()) { a = new ContentControl() { Content = Item.DataContext, ContentTemplate = Column.As <TreeViewTemplateColumn>().Template }; } else if (Column.Is <TreeViewTextColumn>()) { var TextColumn = Column as TreeViewTextColumn; a = new TextBlock() { TextTrimming = TextColumn.TextTrimming }; BindingOperations.SetBinding(a.As <DependencyObject>(), TextBlock.TextProperty, new Binding() { Converter = TextColumn.Converter, Path = new PropertyPath(TextColumn.MemberPath), Mode = BindingMode.OneWay, Source = Item.DataContext }); } BindingOperations.SetBinding(a, FrameworkElement.VisibilityProperty, new Binding() { Converter = new Converters.BooleanToVisibilityConverter(), Path = new PropertyPath("(0)", Linq.DependencyObjectExtensions.IsVisibleProperty), Mode = BindingMode.OneWay, Source = Column }); a.Bind(FrameworkElement.HorizontalAlignmentProperty, new Binding() { Mode = BindingMode.OneWay, Path = new PropertyPath(nameof(Column.HorizontalContentAlignment)), Source = Column, }); a.Bind(FrameworkElement.VerticalAlignmentProperty, new Binding() { Mode = BindingMode.OneWay, Path = new PropertyPath(nameof(Column.VerticalContentAlignment)), Source = Column, }); return(a); }