Getting a FormatString threw an exception

2 posts, 0 answers
  1. Rod
    Rod avatar
    71 posts
    Member since:
    Jan 2011

    Posted 09 Jul 2013 Link to this post

    I've placed a masked numeric input control onto a user control we're working on. When I run the app I get the following error:

    System.Windows.Markup.XamlParseException occurred
      HResult=-2146233087
      Message='Set property 'Telerik.Windows.Controls.RadMaskedInputBase.FormatString' threw an exception.' Line number '291' and line position '48'.
      Source=PresentationFramework
      LineNumber=291
      LinePosition=48
      StackTrace:
           at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
      InnerException: System.FormatException
           HResult=-2146233033
           Message=Format specifier was invalid.

    I'm sure I've done something wrong, but am not sure what. Here's what the XAML looks like right now:

    <telerik:RadMaskedNumericInput x:Name="txtClientNumber" FormatString="D6" MinWidth="80" Margin="3,0"
                                   VerticalContentAlignment="Center" FontSize="15"
                                   Value="{Binding ClientNumber, UpdateSourceTrigger=PropertyChanged}" Mask="#6" />

    What we're trying to do is have the user enter a 6 digit integer value. The data type is an int (in C#), and SQL Server data type is also an int. So, what's the error of my ways?
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 11 Jul 2013 Link to this post

    Hi Rod,

    FormatString determines the way you see the calue in the MaskedInput control when it is not focused.
    For example, with FormatString = "{}{0:n1}"
    The focused control will display 123456 and the unfocused: 123456.0
    So I guess you nedd FormatString = "{}{0:n0}" which will display 123456 in both cases. One of your mistakes is the correct format of the string and the other is using D instead of N.
    Additionaly, you may have to set AutoFillNumberGroupSeparators="False" to remove the separator.
    Let us know if this moves you in the right direction.

    Regards,
    Petar Mladenov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top