如何使用Code后台将字体真棒绑定到Datagrid

时间:2016-08-15 07:16:44

标签: c# wpf data-binding

<DataGridTemplateColumn Header="{x:Static Resources:AppStrings.Tree}">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <Controls:MBFontAwsome MBForeground="{DynamicResource SideBar.Icon.Normal}" MBFontsType="lockIcon" Visibility="{Binding RevLock, Converter={StaticResource BoolToVisibilityConverter}}" MBFontSize="12" />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

我编写了上面的代码,使用XAML将字体真棒绑定到DataGrid模板列。

这很好用,现在勉强使用Code behind file做同样的事情。到目前为止,我已经尝试过这个级别

var projectDocumentColumnHeaderWidth = new DataGridLength(1.0, DataGridLengthUnitType.SizeToHeader);
var collectionToBoolConverter = new CollectionToBooleanConverter();
        /**************************************************************************************/
var faw = new MBFontAwsome();
faw.MBFontsType = MBFonts.documents;
faw.MBFontSize = 12;
faw.Visibility = Visibility.Visible;
var widh = new DataGridLength(1.0, DataGridLengthUnitType.SizeToHeader);
        /***************************************************************************************/
var templateColumn = new DataGridTemplateColumn()
{
    Header = "AttachedProjectDocumentList",
    SortMemberPath = "AttachedProjectDocumentList",
    IsReadOnly = true,
    CellTemplate = new DataTemplate
    {

    }
};
templateColumn.Width = widh;
DoorsGrid.Columns.Add(templateColumn);

如何将字体真棒绑定到单元格?

0 个答案:

没有答案