Obwohl Sie die Standardkonverter locale in WPF gesetzt durch Mamta Dalal vorgeschlagen, da es nicht genug ist, zu konvertieren Drücken Sie die Taste "Dezimal", um die richtige Zeichenfolge einzugeben. Dieser Code wird das korrekte Währungssymbol und Datums-/Uhrzeitformat auf datengebundene Steuerelemente angezeigt
//Will set up correct string formats for data-bound controls,
// but will not replace numpad decimal key press
private void Application_Startup(object sender, StartupEventArgs e)
{
//Among other settings, this code may be used
CultureInfo ci = CultureInfo.CurrentUICulture;
try
{
//Override the default culture with something from app settings
ci = new CultureInfo([insert your preferred settings retrieval method here]);
}
catch { }
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
//Here is the important part for databinding default converters
FrameworkElement.LanguageProperty.OverrideMetadata(
typeof(FrameworkElement),
new FrameworkPropertyMetadata(
XmlLanguage.GetLanguage(ci.IetfLanguageTag)));
//Other initialization things
}
fand ich, dass das Ereignis Fenster weit ist ein wenig sauberer als Textbox spezifisches PreviewKeyDown Handling (es wäre besser, wenn es könnte applikationsweit angewendet werden).
public partial class MainWindow : Window
{
public MainWindow()
{
//Among other code
if (CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator != ".")
{
//Handler attach - will not be done if not needed
PreviewKeyDown += new KeyEventHandler(MainWindow_PreviewKeyDown);
}
}
void MainWindow_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Decimal)
{
e.Handled = true;
if (CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator.Length > 0)
{
Keyboard.FocusedElement.RaiseEvent(
new TextCompositionEventArgs(
InputManager.Current.PrimaryKeyboardDevice,
new TextComposition(InputManager.Current,
Keyboard.FocusedElement,
CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator)
) { RoutedEvent = TextCompositionManager.TextInputEvent});
}
}
}
}
Wenn jemand einen Weg gefunden, könnte es zu setzen applikationsweit ...
Vielen Dank für Vorschlag ... Ich fand auch eine Blog-Post, die mir hilft: http: //www.metanous .be/pharcyde/post/Benutze-the-numeric-keypad-decimal-key-als-the-numeric-separator-für-alle-locales-as-in-Excel.aspx –
LukePet, der prospizierte Link ist bitte kaputt Könntest du mehr im Detail antworten? Vielen Dank. – sthiers
Für VB.NET-Benutzer: https://social.msdn.microsoft.com/Forums/vstudio/en-US/4bedf3c3-be4f-4b2a-b5e0-21c1a41caeca/how-to-use-decimal-separator-in-a- -wpf-textbox-? forum = wpf – Naucle