简体   繁体   English

如何使用IValueConverter转换粗体字体

[英]How can I use IValueConverter to convert a font in bold

Hi I am trying to convert the font style of a row in a DataGrid depending on the type selected by a combobox. 嗨,我正在尝试根据组合框选择的类型来转换DataGrid中一行的字体样式。 I'm not getting and is returning the following error: 我没有得到并返回以下错误:

"Error 18 'System.Windows.Documents.Bold' does not contain a constructor que takes 1 arguments “错误18'System.Windows.Documents.Bold'不包含构造函数,que需要1个参数

This is my class: 这是我的课:

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.IO;
using System.Windows.Media.Imaging;

namespace enLoja.enLoja_Web.Helpers
{
    public class GrupoBoldConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var weight = new Bold(FontWeights.Normal);
            switch (int.Parse(value.ToString()))
            {
                case 2:
                    weight = new Bold(FontWeights.Bold);
                    break;
                default:
                    weight = new Bold(FontWeights.Normal);
                    break;
            }
            return weight;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}

And here is how I decorate my datagrid: 这是我装饰数据网格的方式:

<sdk:Page.Resources>
    <Helpers:GrupoBoldConverter x:Key="BoldConverter" />
</sdk:Page.Resources>

... ...

<sdk:DataGrid.RowStyle>
    <Style TargetType="sdk:DataGridRow">
        <Setter Property="FontWeight" Value="{Binding SINTETICO, Converter={StaticResource BoldConverter}}" />
    </Style>
</sdk:DataGrid.RowStyle>

I know that the syntax error is. 我知道语法错误是。 My problem is that I can not use the correct option. 我的问题是我无法使用正确的选项。 I thank anyone who can help. 我感谢任何可以提供帮助的人。

The FontWeight property expects a FontWeight not a Bold . FontWeight属性期望FontWeight不是Bold Return just the FontWeight from your converter. 从转换器仅返回FontWeight

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在WPF中使用IValueConverter绑定到对象的不同属性? - How can I use an IValueConverter to bind to different properties of an object in WPF? 如何在 IValueConverter 中使用 targetType 参数? - How do I use the targetType parameter in an IValueConverter? 如何在(Xamarin.Forms)XAML中使用IValueConverter转换完整的对象? - How can I convert a complete object with IValueConverter in (Xamarin.Forms) XAML? C#:如何将以粗体显示的日期添加到RichTextBox中,但继续以常规字体(非粗体)书写 - C#: How can I add the DATE in BOLD into a RichTextBox but keep writing in regular font (not BOLD) 如何在Linq中绑定IValueConverter以转换属性 - How to bind an IValueConverter in Linq to convert the properties 如何在PDFsharp中使用等宽字体? - How can I use a monospace font with PDFsharp? 我应该使用IValueConverter的targetType参数吗? - Should I use the targetType parameter of the IValueConverter 我可以将整个 UI 元素传递到 IValueConverter 吗? - Can I pass entire UI element into a IValueConverter? 为什么不能使用“ yield”运算符在IValueConverter中返回懒惰列表? - Why can't I use “yield” operator to return a lazy list in IValueConverter? 如何使用另一个文件中的 IValueConverter 实现? - How to use IValueConverter implementation from another file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM