Aunque es posible establecer la configuración regional convertidor predeterminado en WPF como sugiere Mamta Dalal no es suficiente para convertir la tecla "decimal" presiona la cadena correcta. Este código se mostrará el símbolo de moneda correcta y formato de fecha/hora en los controles enlazados a datos
//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
}
me encontré con que el manejo de la PreviewKeyDown evento ventana ancha es un poco más limpio que el cuadro de texto específico (que sería mejor si podría aplicarse en toda la aplicación).
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});
}
}
}
}
Si alguien pudiera llegar a una manera de establecer que sea aplicable en toda ...
Gracias por la sugerencia ... también encontré un blog que me ayuda: http: //www.metanous .be/pharcyde/post/Use-the-numeric-keypad-decimal-key-as-the-numeric-separator-for-all-locales-as-in-Excel.aspx –
LukePet, el enlace propsoed está roto, por favor podría responder más en detalles. Gracias. – sthiers
Para usuarios de VB.NET: 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