0
我有一个DataGrid
和先前我在列标题使用以下Style
仅显示图像/图标。同时显示图像和标签在数据网格列标题
<Style TargetType="DataGridColumnHeader" >
<Setter Property="ContentTemplate" >
<Setter.Value>
<DataTemplate >
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Converter={StaticResource StrToImageConverter}}" />
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
我传递在我DataTable
string colName; // Some file path
DataColumn c = new DataColumn(colName) { DataType = typeof(string) };
dt.Columns.Add(c);
和StrToImageConverter
其转换为位图图像路径作为列名。
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
ImageSource result = null;
string path = (string)value;
if (!string.IsNullOrEmpty(path))
result = new BitmapImage(new Uri(path));
return result;
}
但是现在我还必须显示列名作为文本以及图标。我可以在图片旁边的StackPanel
中添加一个TextBlock
,但我不确定如何将数据传递给它,或者它甚至是最佳方法。
任何帮助将非常感激。
谢谢