Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1048715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:30:07+00:00 2026-05-16T16:30:07+00:00

Q: Why does my custom TextBox UserControl using a MultiBinding and IMultiValueConverter gets its

  • 0

Q: Why does my custom TextBox UserControl using a MultiBinding and IMultiValueConverter gets its Convert() method called only once (during instanciation) ??

I have defined a UserControl that requires a MultiBinding and a IMultiValueConverter in order to change its behavior/presentation upon 2 indenpendant DependencyProperty.

<proj:MyControl Value="10" Digits="1" />

UserControl:

<UserControl x:Class="MyControl"
             x:Name="uc"
             ...>

    <UserControl.Resources>
        <conv:DecimalToStringMultiConverter x:Key="DecToString" />
    </UserControl.Resources>

    [...]

    <Grid>
        <ctrl:VTextBox x:Name="vTb" Grid.Column="0" Margin="0,0,2,0">
            <ctrl:VTextBox.Text>
                <MultiBinding Converter="{StaticResource DecToString}" UpdateSourceTrigger="LostFocus" Mode="TwoWay">
                    <Binding ElementName="uc" Path="Value" Mode="TwoWay" />
                    <Binding ElementName="uc" Path="Digits" Mode="TwoWay" />
                </MultiBinding>
            </ctrl:VTextBox.Text>
        </ctrl:VTextBox>
    </Grid>
</UserControl>

When executing the application, the UserControls are all correctly instanciated. However, the IMultiValueConverter.Convert() method gets called only once.

Using an simple Binding + IValueConverter with a constant ConvertParameter worked great: the converter’s Convert() method would get called everytime the TextBox contained inside the UserControl had its Text property changed.

Design changed and I had to resort to using a MultiBinding + IMultiValueConverter, and now the Convert() method only gets called once, and the TextBox.Text property is never updated upon the LostFocus() event.

What gives?

The MultiValueConverter is defined as below. I just wrap the IMultiValueConverter upon the IValueConverter to reuse existing code.

[ValueConversion(/*sourceType*/ typeof(Decimal), /*targetType*/ typeof(string))]
public class DecimalToStringConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value == null)
            return "0.00";

        int? digits = parameter as int?;

        if(digits == null)
            digits = 2;

        NumberFormatInfo nfi = (NumberFormatInfo) CultureInfo.InvariantCulture.NumberFormat.Clone();
        nfi.NumberGroupSeparator = " ";
        nfi.CurrencyDecimalSeparator = ".";
        nfi.NumberDecimalDigits = (int)digits;

        return ((decimal)value).ToString("n", nfi);
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value == null)
            return 0.00m;

        decimal d;

        return decimal.TryParse((string)value, out d) ? d : 0.00m;
    }
}

[ValueConversion(/*sourceType*/ typeof(Decimal), /*targetType*/ typeof(string))]
public class DecimalToStringMultiConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        DecimalToStringConverter conv = new DecimalToStringConverter();
        return conv.Convert(values[0], targetType, values.Length > 1 ? values[1] : null, culture);
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
    {
        DecimalToStringConverter conv = new DecimalToStringConverter();
        return new[] { conv.ConvertBack(value, targetTypes[0], null, culture) };
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T16:30:08+00:00Added an answer on May 16, 2026 at 4:30 pm

    It seems like you have some conflicting expectations about the updating behavior of the Binding and TextBox. The only reason Convert will be called multiple times is if the values of Digits or Value change multiple times, and there is nothing in your posted code to indicate that will happen. Changes to TextBox.Text won’t cause calls to Convert, but should instead be calling ConvertBack on every change+LostFocus. Are you seeing that when you run your code?

    You also need to return two values, instead of the one there now, from your ConvertBack method in order to supply both of the Bindings used in the MultiBinding with values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know if its possible to turn off dreamweavers custom icons that it
Does anyone know how to check if the called ui (custom) has also options
We have a custom WPF control with multiple TextBox . Each TextBox has its
I have a custom UserControl (a label and a textbox). My problem is I
I have a custom login usercontrol that has a normal textbox and a passwordbox.
Does a custom control (ascx) get rendered regardless of whether visibility property is true
How does Branchout custom their Request Dialog messages? There is no option for this.
I have a custom FrameLayout class which does some custom drawing on the OnSizeChanged
There are a few things that the custom grid does that you cannot do
does anybody know how i can access a custom cell within the - (void)tableView:commitEditingStyle:forRowAtIndexPath:.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.