Chociaż można ustawić domyślne ustawienia regionalne konwerter w WPF jak sugeruje Mamta Dalal to nie wystarczy do konwersji klawisz "dziesiętny" naciśnij odpowiedni ciąg znaków. Ten kod wyświetli prawidłowy symbol waluty i format daty/czasu na kontrole danych związana
//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
}
stwierdziliśmy, że posługiwania sie previewKeyDown wydarzenie okno szerokości jest trochę czystsze niż textbox specyficzne (byłoby lepiej, gdyby może być stosowany w całej aplikacji).
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});
}
}
}
}
Jeśli ktoś mógłby wymyślić sposób, aby ustawić go w całej aplikacji ...
Dzięki za sugestię ... Ja również znaleźć na blogu, że mi pomaga: http: //www.metanous .be/pharcyde/post/Use-the-numeric-keypad-decimal-key-as-the-numeric-separator-for-all-locales-as-in-Excel.aspx –
LukePet, propsoed link jest uszkodzony, proszę czy mógłbyś bardziej szczegółowo odpowiedzieć? Dzięki. – sthiers
Dla użytkowników 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