有一個datatable,當我們沒有值時,它將被插入到doubl.NaN。 我想要做的是每當我看到double.Nan我希望把「 - 」來代替,因此我有下面的代碼轉換器:將double.NaN轉換爲轉換器中的相關文化wpf
if (value.ToString() == double.NaN.ToString())
{
return "-";
}
一切都工作在「EN-US」文化,但是當我們使用不同的文化(如「zn-cn」) 它不起作用,因爲「double.NaN.ToString()」結果與中文單詞其中value.ToString()是正常的「NaN」 。
我嘗試使用double.parse()使用轉換器,沒有任何工作。
更新 -確定的問題是轉換器獲取對象的字符串,而不是作爲雙倍這是XAML中:
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border Background="Transparent" Padding="10 8" BorderBrush="Transparent" BorderThickness="1">
<Border.Resources>
<Style TargetType="ToolTip">
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="HasDropShadow" Value="False"/>
<Setter Property="VerticalOffset" Value="-46"/>
<Setter Property="HorizontalOffset" Value="10"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToolTip">
<General:TextTooltip TitleStyle="{StaticResource NumericTableToolTipTitleStyle}" Content="{TemplateBinding Content}" ContentStringFormat="G" ContentStyle="{StaticResource NumericTableToolTipContentStyle}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Border.Resources>
<TextBlock x:Name="tbCellText" Text="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=Content.Text, Converter={StaticResource NumericTableCellContentConverter}, ConverterCulture={x:Static gl:CultureInfo.CurrentCulture}}"
ToolTip="{Binding ElementName=tbCellText, Path=Text}"
TextWrapping="Wrap"/>
</Border>
</ControlTemplate>
有沒有什麼辦法來保護對象的類型?
我知道我只能做一個與「NaN」的比較,但我想要更通用的解決方案。
順便說一句,轉換器已將converterculture作爲參數之一 – Vlad 2012-07-19 14:58:23
是啊,我知道,但它不會幫助,只要值是字符串類型... – 2012-07-19 15:02:45
@OriPrice看到我的答案,你綁定了錯誤的屬性。 – 2012-07-19 15:35:36