이 코드를 사용하여 이미지와 텍스트를 표시하는 열을 만들지 만 텍스트 만 표시됩니다. 내가 뭘 잘못하고 있습니까?이미지 및 텍스트 WPF로 DataGridTemplateColumn 만들기
DataGridTemplateColumn col1 = new DataGridTemplateColumn(); col1.Header = "MyHeader";
FrameworkElementFactory factoryStackPanel = new FrameworkElementFactory(typeof(System.Windows.Controls.StackPanel));
factoryStackPanel.SetValue(System.Windows.Controls.StackPanel.OrientationProperty, Orientation.Vertical);
FrameworkElementFactory factoryTextBlock = new FrameworkElementFactory(typeof(System.Windows.Controls.TextBlock));
Binding bindTextBlock = new Binding("[" + i + "]");
factoryTextBlock.SetValue(System.Windows.Controls.TextBlock.TextProperty, bindTextBlock);
factoryTextBlock.SetValue(System.Windows.Controls.TextBlock.TextWrappingProperty, TextWrapping.Wrap);
factoryTextBlock.SetValue(System.Windows.Controls.TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
FrameworkElementFactory factoryImage = new FrameworkElementFactory(typeof(System.Windows.Controls.Image));
Binding bindImage = new Binding("http://www.pgn.co.id/images/modules/logo_pgn.png");
factoryImage.SetValue(System.Windows.Controls.Image.SourceProperty, bindImage);
factoryStackPanel.AppendChild(factoryImage);
factoryStackPanel.AppendChild(factoryTextBlock);
DataTemplate cellTemplate = new DataTemplate() { VisualTree = factoryStackPanel };
col1.CellTemplate = cellTemplate;
gridViewItens.Columns.Add(col1);
그것은 XAML에서이 물건을 할 훨씬 쉽다. –