0
私はTextModelを持ち、viewmodelのプロパティにバインドされています。また、コンバータを使用して10進値を通貨値に変換しています。たとえば、255を入力すると、テキスト値は$ 255と表示されます。しかし、それは動作していないようです。OnPropertyChangedはNULL値の10進数型wpfで動作しません
<TextBox Margin="479,69,0,0"
Height="24"
Text="{bindingDecorators:CurrencyBinding FleetAggregate, Mode=TwoWay, Converter={StaticResource DecimalToCurrencyConverter}}" />
VMプロパティ
public decimal? FleetAggregate
{
get { return FleetRatesRow.HasStandardAggregate ? (decimal?)FleetRatesRow.fleet_pa_aggregate : (decimal?)null; }
set
{
if (!value.HasValue)
{
FleetRatesRow.Setfleet_pa_aggregateNull();
OnPropertyChanged();
return;
}
FleetRatesRow.fleet_pa_aggregate = value.Value;
OnPropertyChanged();
}
}
あなたがコンバータを使用する代わりにStringFormat
を使用することができ
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
try
{
var currencyFormatArg = parameter == null ? new CurrencyFormatArg() : (CurrencyFormatArg)parameter;
if (value == null)
{
return currencyFormatArg.AllowNull ? string.Empty : DependencyProperty.UnsetValue;
}
var currencyValue = (decimal)value;
string format = currencyValue < 0
? '-' + currencyFormatArg.Format
: currencyFormatArg.Format;
string codePrefix = currencyFormatArg.ShowCode ? currencyFormatArg.CurrencyCode + " " : string.Empty;
return
codePrefix +
string.Format(format, currencyFormatArg.CurrencySymbol, Math.Abs(currencyValue));
}
catch (Exception)
{
return DependencyProperty.UnsetValue;
}
}