如何在DataGridTextColumn中将XAML中的双值格式化为德文格式? [英] How do I format a double value in XAML to German format on a DataGridTextColumn?
问题描述
//显示#。##
< DataGridTextColumn Header =Sum ValueBinding ={Binding SumValue}/>
在这种情况下,请尝试几个选项:
A。全球设置语言文化为整个应用程序,它可以解决与当前语言文化相关的一些问题。
添加启动
事件 App.xaml
,它建立了必要的语言文化。它影响日期的显示,双重值,金额等。
XAML
<应用程序x:Class =DataGridTargetUpdateHelp.App
xmlns =http://schemas.microsoft.com / winfx / 2006 / xaml / presentation
xmlns:x =http://schemas.microsoft.com/winfx/2006/xaml
StartupUri =MainWindow.xaml
启动= Application_Startup >
< Application.Resources>
< /Application.Resources>
< / Application>
代码隐藏
public partial class App:Application
{
private void Application_Startup(object sender,StartupEventArgs e)
{
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement),
new FrameworkPropertyMetadata(System.Windows.Markup.XmlLanguage.GetLanguage(de-DE))); // CultureInfo.CurrentCulture.IetfLanguageTag返回当前的语言代码
}
}
< blockquote>
B。使用 DataGridTemplateColumn
在这种情况下,您可以设置任何 Control
在DataGridCell中显示值:
< DataGrid.Columns>
< DataGridTemplateColumn Header =ID>
< DataGridTemplateColumn.CellTemplate>
< DataTemplate>
< TextBlock Text ={Binding Path = ID,StringFormat = {} {0:N2}}xml:lang =de-DE/>
< / DataTemplate>
< /DataGridTemplateColumn.CellTemplate>
< / DataGridTemplateColumn>
< /DataGrid.Columns>
I have this simple piece of code and I am wondering how to convert it to German format (#.###,##) ?
// displays #.##
<DataGridTextColumn Header="Sum Value" Binding="{Binding SumValue}"/>
In this case try several options:
A. Global setting language culture for the entire application, it can solve some problems related to the current language culture.
Add Startup
event for App.xaml
, which establishes the necessary language culture. It affects the display of the date, double values, sums of money, etc:
XAML
<Application x:Class="DataGridTargetUpdateHelp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml"
Startup="Application_Startup">
<Application.Resources>
</Application.Resources>
</Application>
Code-behind
public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement),
new FrameworkPropertyMetadata(System.Windows.Markup.XmlLanguage.GetLanguage("de-DE"))); // CultureInfo.CurrentCulture.IetfLanguageTag return the current code of language
}
}
B. Use the
DataGridTemplateColumn
In this case you can set any Control
to display values in the DataGridCell:
<DataGrid.Columns>
<DataGridTemplateColumn Header="ID">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=ID, StringFormat={}{0:N2}}" xml:lang="de-DE" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
这篇关于如何在DataGridTextColumn中将XAML中的双值格式化为德文格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!