microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.32k stars 677 forks source link

NumberBox parsing #9772

Open tpoint75 opened 3 months ago

tpoint75 commented 3 months ago

The NumberBox is not good for entering big Numbers

The basses type is double but I cant enter scientific notation like: "1e6" or "1M". Therefore it would be good to be able overwrite the INumberParser like this:

struct CustomNumberParser : winrt::implements<CustomNumberParser, winrt::Windows::Globalization::NumberFormatting::INumberParser>
{
    winrt::Windows::Foundation::IReference<int64_t> ParseInt(winrt::hstring const& text)
    {
        try
        {
            int64_t value = std::stoll(std::wstring(text));
            return winrt::Windows::Foundation::IReference<int64_t>(value);
        }
        catch (...)
        {
            return nullptr;
        }
    }

    winrt::Windows::Foundation::IReference<uint64_t> ParseUInt(winrt::hstring const& text)
    {
        try
        {
            uint64_t value = std::stoull(std::wstring(text));
            return winrt::Windows::Foundation::IReference<uint64_t>(value);
        }
        catch (...)
        {
            return nullptr;
        }
    }

    winrt::Windows::Foundation::IReference<double> ParseDouble(winrt::hstring const& text)
    {
        try
        {
            double value = std::stod(std::wstring(text));
            return winrt::Windows::Foundation::IReference<double>(value);
        }
        catch (...)
        {
            return nullptr;
        }
    }
};

An other way to do it, is to have a TextChanged event. Together with ValidationMode="Disabled" I could parse the value there. But this is a bit more to do.

The best scenario is to have it build in, with a property to be able to change its behavior.

It would be nice to have the ability to increase the increment of the spin buttons if the spin button is pressed and hold. (The longer the bigger should be the increase of the value.)

An other thing that has proven in the past, is to increase the value inside the NumberBox by the position of the cursor inside the number.

tpoint75 commented 1 month ago

Any news on this?