[英]How can I use an IValueConverter to bind to different properties of an object in WPF?
[英]How can I use IValueConverter to convert a font in bold
嗨,我正在嘗試根據組合框選擇的類型來轉換DataGrid中一行的字體樣式。 我沒有得到並返回以下錯誤:
“錯誤18'System.Windows.Documents.Bold'不包含構造函數,que需要1個參數
這是我的課:
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();
}
}
}
這是我裝飾數據網格的方式:
<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>
我知道語法錯誤是。 我的問題是我無法使用正確的選項。 我感謝任何可以提供幫助的人。
FontWeight
屬性期望FontWeight不是Bold
。 從轉換器僅返回FontWeight
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.