WPF DataGrid显示点而不是逗号

时间:2017-03-17 13:33:01

标签: wpf vb.net xaml

在网上挖掘并搜索没有结果的答案后,我想请求您的帮助。我有一个SQL数据库表有2列(浮点数据类型,例如1,2 1,3 1,4等)

like this

绑定到<CollectionViewSource x:Key="Tab_LosTab_PolterTab_PoltersektionViewSource" Source="{Binding Tab_Polter_Tab_Poltersektion, Source={StaticResource Tab_LosTab_PolterViewSource}}"/> <DataGrid x:Name="Tab_PoltersektionDataGrid" IsReadOnly="False" AutoGenerateColumns="False" EnableRowVirtualization="True" ItemsSource="{Binding Source={StaticResource Tab_LosTab_PolterTab_PoltersektionViewSource}}" Margin="10,250,10,60" RowDetailsVisibilityMode="VisibleWhenSelected"> <DataGrid.Columns> <DataGridTextColumn x:Name="Polter_H_vornColumn" Binding="{Binding Polter_H_vorn}" Header="Polterhöhe vorn" Width="*"/> <DataGridTextColumn x:Name="Polter_H_hintenColumn" Binding="{Binding Polter_H_hinten}" Header="Polterhöhe hinten" Width="*"/> </DataGrid.Columns> </DataGrid>

like this

XAML代码:

Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles MyBase.Loaded
    Dim DataSet1Tab_PoltersektionTableAdapter As PV.DataSet1TableAdapters.Tab_PoltersektionTableAdapter = New PV.DataSet1TableAdapters.Tab_PoltersektionTableAdapter()
    DataSet1Tab_PoltersektionTableAdapter.Fill(DataSet1.Tab_Poltersektion)
    Dim Tab_LosTab_PolterTab_PoltersektionViewSource As System.Windows.Data.CollectionViewSource = CType(Me.FindResource("Tab_LosTab_PolterTab_PoltersektionViewSource"), System.Windows.Data.CollectionViewSource)
    Tab_LosTab_PolterTab_PoltersektionViewSource.View.MoveCurrentToFirst()
End Sub

和Vb.Net代码:

DataGrid

我的问题是我的import { Accounts } from 'meteor/accounts-base' //get old email const oldEmail = Meteor.users.findOne(this.userId).emails[0].address; //add new email Accounts.addEmail(this.userId, args.email); //remove old email Accounts.removeEmail(this.userId, oldEmail); 以这种方式显示这些值:1.2 1.3 1.4我需要它们显示如下:1,2 1,3 1,4等当我尝试编辑某些值时并输入1,2,它返回12.我的PC语言首选项设置为欧洲。有什么建议吗?

1 个答案:

答案 0 :(得分:1)

您可以使用IValueConverter来处理此问题。

public class GermanNumberConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return ((float)value).ToString(CultureInfo.CreateSpecificCulture("de-DE"));
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return float.Parse(value.ToString());
    }
}

在您的xaml代码中,您可以像

一样使用此转换器
<DataGridTextColumn Binding="{Binding Polter_H_hinten, Converter={StaticResource GermanNumberConverter}}" />

您还必须在Window中指定转换器。

<Window.Resources>
    <ResourceDictionary>
        <c:GermanNumberConverter x:Key="GermanNumberConverter" />
    </ResourceDictionary>
</Window.Resources>