【发布时间】:2013-11-17 15:57:27
【问题描述】:
我在我的 WPF 应用程序中使用 Telerik Grid。如果我在 XAML 中定义所有内容,它可以正常工作,图像列也是如此:
<!-- IsActiveGroup -->
<telerik:GridViewDataColumn DataMemberBinding="{Binding IsActiveGroup}" Width="45">
<telerik:GridViewDataColumn.Header>
<TextBlock Text="Column name" ToolTip="Some tooltip"/>
</telerik:GridViewDataColumn.Header>
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding Path=IsActiveImageSource, Converter={StaticResource imgConverter}}" Stretch="UniformToFill" RenderOptions.BitmapScalingMode="HighQuality" Width="20" Height="20" ToolTip="{Binding IsActiveGroup}" />
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>
但是,我必须以编程方式执行此操作,但我不知道如何执行此操作。我试过了:
var column = new GridViewDataColumn();
column.UniqueName = uniqueName;
var headerTextBlock = new TextBlock();
headerTextBlock.Text = headerText;
headerTextBlock.ToolTip = headerTooltip;
column.Header = headerTextBlock;
var factory = new FrameworkElementFactory(typeof(Image));
factory.SetValue(Image.SourceProperty, new Binding("IsActiveImageSource")
{
Converter = new BinaryImageConverter()
});
factory.SetValue(Image.StretchProperty, Stretch.UniformToFill);
var cellTemplate = new DataTemplate() { VisualTree = factory };
column.CellTemplate = cellTemplate;
this.gridView.Columns.Add(column);
但这并没有做任何事情,我也不知道如何设置 RenderOptions。
谁能帮忙?
谢谢!
【问题讨论】:
-
什么都不做是什么意思?未添加列/模板错误/值错误?
标签: c# wpf xaml telerik datatemplate