[英]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.