Hi I am trying to convert the font style of a row in a DataGrid depending on the type selected by a combobox. 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
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
. Return just the FontWeight
from your converter.