C
C#2y ago
Elio

❔ WPF Textbox decimal only

Hello, i'd like to know how we are supposed to configure our textbox in order to accept only decimal number ? Currently i've this but i do not find a ny good way to do it
15 Replies
Elio
Elio2y ago
sibber
sibber2y ago
wpf?
Elio
Elio2y ago
yes
sibber
sibber2y ago
handle PreviewTextInput and validate set eventArgs.Handled to true if its not valid
Elio
Elio2y ago
so i had this PreviewKeyDown="TextBox_PreviewKeyDown" then i just write some code in the method in order to select only the key i want. That it ?
sibber
sibber2y ago
no PreviewTextInput not KeyDown then you check if the text is valid, in your case if its a decimal number
Elio
Elio2y ago
aww ok cause preview key check only the last key pressed instead of the whole text i will look some regex expression or something like this thanks i didn't know there was preview event
sibber
sibber2y ago
sure you can also use TryParse
Elio
Elio2y ago
i will do that once i've make sure that my string is a decimal 🙂
sibber
sibber2y ago
you can use that to check if its a decmial
Elio
Elio2y ago
oohhhh i thought it just convert my number from string to double or others
sibber
sibber2y ago
also returns whether it can be converted or not
Elio
Elio2y ago
insane 😮 now i just need to avoid multple dot thanks a lot you give me all the int i needed
sibber
sibber2y ago
np
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
maui deserialize problemI am having a problem when trying to deserialize api data ```C# string content = await response.C❔ Log from helper class without creating new context? (Serilog)I have a bunch of services with their own dedicated loggers that have config'd settings for filterin❔ Swagger Open API not showing Request examples in the UII've written an Azure Function with Open API in C#, but when I open up the Swagger/UI to test my AzuLooking solution for get query from _dbContext.SaveChangesAsync() for save logs and easier debuggingHello, i have a .net core 6.0 app that save entites in MSSQL database with EfCORE 6.0 so my function❔ I'm building an MVC core webshop. How should I be structuring controllers, actions and views?So, right now, I have one single view, and this view renders both information about the product and ❔ How to make an object follows my mouse?so I am new at programming and trying to make a top down shooting games in windows form app. My lect❔ Is this the right way to implement an Interface```csharp interface IObstacles { void Draw(Graphics g); } class Redbox : IO❔ Is there any tool converting csv file to Class (seeding data)?I am using EF to seed data and I have an excel file containing like 500 records. If that's around 1❔ Is it possible to have WPF window hidden until Blazor WebView loads page?I'm trying to hide a WPF window until the Blazor WebView loads, but it seems that the initialization❔ SQLite in-memory Database read from ReadOnlyMemory bytesI'm receiving an SQLite database payload from an AMQP-0-9-1 message in the form of `ReadOnlyMemory<b