2013-05-01 72 views
0

嗨我想要根據組合框選擇的類型轉換DataGrid中的行的字體樣式。我沒有收到,並返回以下錯誤:我如何使用IValueConverter轉換爲粗體的字體

"Error 18 'System.Windows.Documents.Bold' does not contain a constructor que takes 1 arguments

這是我的課:

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(); 
     } 
    } 
} 

,這裏是我如何裝飾我的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> 

我知道語法錯誤是。我的問題是我無法使用正確的選項。 我感謝任何可以幫助的人。

回答

1

FontWeight財產預計FontWeight不是Bold。從您的轉換器只返回FontWeight

+0

我試過這種方式: var weight = new FontWeight(FontWeights.Normal); 而仍然收到相同的錯誤。 – 2013-05-01 14:20:08